+ 2

How do i get the total to show correctly?

I am trying to get the bill amount plus the tip amount (not the percentage) to equal the total bill. I have got it up the point where it will read for example: bill: 100 tip is 18.00 total bill reads 10018.00 instead of 118.00. The part of the javascript that I am having issues with is currently commented out until i could get it working. Can someone help me understand what I am doing wrong? https://code.sololearn.com/WHP5eqGTrolT/?ref=app

22nd Apr 2019, 11:46 PM
Ryan Lusby
Ryan Lusby - avatar
4 Réponses
+ 3
https://www.w3schools.com/jsref/jsref_number.asp Number(document.getElementById("billamt").value) + Number(document.getElementById("tipamt").textContent)
23rd Apr 2019, 9:56 PM
ODLNT
ODLNT - avatar
+ 3
Ryan Lusby The Input Text Object property value returns a string. So if document.getElementById("billamt").value is 100 it is actually "100" and the same is true for document.getElementById("tipamt").textContent. You need to convert the values to an integer by using parseInt() or Number().
23rd Apr 2019, 1:53 AM
ODLNT
ODLNT - avatar
+ 2
Thank you i believe you are right and have read up more on Number() but i dont seem to be using it correctly. Would you be able to show me an example?
23rd Apr 2019, 8:33 PM
Ryan Lusby
Ryan Lusby - avatar
+ 2
Thank you! That was a big help. I was deifinately using it wrong.
23rd Apr 2019, 10:15 PM
Ryan Lusby
Ryan Lusby - avatar