+ 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
4 Answers
+ 3
https://www.w3schools.com/jsref/jsref_number.asp
Number(document.getElementById("billamt").value) +
Number(document.getElementById("tipamt").textContent)
+ 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().
+ 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?
+ 2
Thank you! That was a big help. I was deifinately using it wrong.