Skip to content Skip to sidebar Skip to footer

Javascript Function To Add Two Numbers Is Not Working Right

My code in HTML takes a user input number in, and it does a calculation and then displays the output. The user chosen input is put into a formula and the result of the formula is a

Solution 1:

HTML DOM element properties are always strings. You need to convert them to numbers in your usage.

parseInt(form.resistance.value);
parseFloat(form.resistance.value);
+form.resistance.value;

(Any of the three will work; I prefer the first two (use parseInt unless you're looking for a float).)

Solution 2:

It's because it's treating the values as a string.

form.resistance.value + Rchange are both strings, so it's appending it.

Use the parseInt JavaScript method to get the decimal version.

Post a Comment for "Javascript Function To Add Two Numbers Is Not Working Right"