Forum Moderators: open
checkvals = "4-4-3";
checkvals = checkvals.split('-');
var counter = new Number;
for (x = 0; x < checkvals.length; x++) {
num = checkvals[x];
counter -= num;
}
document.write(counter+"<br />");
document.write(counter.replace(/-/, ""));
(in case you're wondering why i've used '-=' instead of '+=', well my stupid browser (FF that is) seems to put the numbers together instead of adding them up!)
checkvals = "4-4-3";
checkvals = checkvals.split('-');
var counter = 0;
for (x = 0; x < checkvals.length; x++) {
num = parseInt(checkvals[x]);
counter += num;
}
document.write(counter+"<br />");
Since the numbers were in a string format, they were concatenated instead of added.
Good luck!
It can be annoying at times, however, it is something us web programmers cannot live without ;)