discount calculator
I realise a discount calculator
who should show on the bottom :
first: the name of the product
second: the price
and the discount
this is my work :
https://codepen.io/alpha_66/pen/oNVwgOG?editors=1010
but somthing is going wrong can I get some idea about what is going wrong ?
thanks by advance
25 Replies
you are trying to have an evenlistener on the select options.
to get the value of the selected option, you can add the change evenlistener to the select itself
example
Hi everybody
thanks for your message
a change my code
but something is still going wrong
what I write in filed don t appear on the bottom
can I get some idea about what is going wrong
thanks
you only have an event listener on the level dropdown, so it only updates when you change the level
thanks
I want get two number after ","
but I have zero
my code
you can use
Number.toLocaleString()
in combination with the options and Intl.NumberFormat() Constructor
syntax to get a locale formatted currency string:
or just set it to two digits:
the first one will follow all the rules for displaying currency in French. It adds the € at the end, and will handle negative numbers gracefully. And if you change the locale to en-US, it'll change to using a period decimal separator and put the € at the start.thanks you
please I have an message
I don t understand
the code is
you're setting
first
to the value of the first option in the dropdown, which is a string. Strings can't have eventlisteners, those can only go on html elementsyou dont need the evenlisteners on the options if you have it on the select.
forget about first,two,three. you don't need them.
level.value is already the selected option
also, in this case it would be easier to use a form element, so you only have to listen to a change on that instead of all fields
here a very simple example of your project
https://codepen.io/MarkBoots/pen/gOERXvr?editors=1011
Thanks a lot for every answers
I have a question
when I wrote this :
code doesn't run after
return
but when I wtitte this :
is working fine
when you use
return
, the value you pass it is returned and the function stops executing immediatelyok
some editors and setups will actually gray out the code after a return statement, and warn about unreachable code
another question when I used .fixed(); he don t work
not sure tbh, that should work (and set it to 1 decimal place)
there is nothing to return to. this is just an evenlistener's callback.
what do you want to do with remise?
I think you want to do
discount.innerHTML=remise.toFixed(1)
and no returnthat is a good point
thanks a lot guys