Skip to content Skip to sidebar Skip to footer

Javascript Counter Variable Not Incrementing Only Appending Digits

var counter = 0; var userAdd = prompt('How many would you like to add?'); counter += userAdd; console.log(counter); New to javascript. I am trying to get the counter t

Solution 1:

You need to type your result as an int rather than a string.

var userAdd = parseInt(prompt("How many would you like to add?"));

This forces the numeric adding instead of the string appending.

Post a Comment for "Javascript Counter Variable Not Incrementing Only Appending Digits"