Problem with sum in JavaScript Posted June 10, 2019 Hi, I'm trying to create a little program to calculate the income with a tax, but i've got a problem. Instead of sum the 2 numbers, it aggregate them Here the example: Price = 100 Rate = 0.05 Tax = Price * Rate -> 100 * 0.05 = 5 Income = Price + Tax = 100 + 5 = 105 (but the result I obtain is 1005) I want to specify that the Price is get from a input. Here the code <!DOCTYPE html> <html> <body> <h1>Test</h1> <input id="price" type="number" onchange="income()"> <p id="result"></p> <script> function income(){ let price = document.getElementById("price").value; let rate = 0.05; let tax = price * rate; let income = price + tax; document.getElementById("result").innerHTML ="The income is: " + income; } </script> </body> </html> How can i fix it?
Problem with sum
in JavaScript
Posted
Hi,
I'm trying to create a little program to calculate the income with a tax, but i've got a problem. Instead of sum the 2 numbers, it aggregate them
Here the example:
Price = 100
Rate = 0.05
Tax = Price * Rate -> 100 * 0.05 = 5
Income = Price + Tax = 100 + 5 = 105 (but the result I obtain is 1005)
I want to specify that the Price is get from a input.
Here the code
How can i fix it?