Skip to content Skip to sidebar Skip to footer

Javascript Variables Not Adding, Only Concatenating As Strings

I have some simple code that should add two numbers and it seems to keep adding them, i.e. if I have a variable that is initialized as 0 , I add 100 once, and then I add 200, it se

Solution 1:

var total = +score + +amount;

This line is confusing to me. If you want to add score and amount to total, use

var total += score + amount;

Post a Comment for "Javascript Variables Not Adding, Only Concatenating As Strings"