View Full Version : Addition Operator

08-26-2007, 03:31 AM
In most of my scripts concerning math operators, I use prompts. The bad thing about prompt variables is that, although you can subtract, multiply, and divide them normally, addition treats the variables as strings, and does not add the values. This has proven to be an annoying problem, and although I have found a solution through loops and an if statement, suffice to say it is inconvenient, and does not work with decimals. I noticed that when I declared the variables myself, they are added as numbers not strings, because the variable is a number. Is there a way to make a variable declared through prompt a definite number so addition does not add strings?

PS: By prompt I mean

var a = prompt("Type in a number here", "")

08-26-2007, 04:00 AM
var a = Number(prompt("Type in a number here", ""));

08-26-2007, 04:12 AM
Thanks a lot, this saves a lot of time.