March 24th, 2013, 02:01 AM
-
Concatenation vs addition, help appreciated
Hey
I'm taking a beginner class and an assignment I was given was to create an equation with JavaScript that web viewers could use with whatever inputs they chose. Here's the source code:
javascript Code:
var a;
var b;
var c;
a = prompt("a =");
b = prompt("b =");
c = prompt("c =");
var result;
result = a + b + c;
alert(result);
My problem is that
concatenates the values instead of adding them; I searched and found that applying parseInt(variable) fixes this and tried it with success, but I was wondering if there is a simpler way, a function that performs "result = a + b + c" with addition rather than concatenation. I've tried various incarnations of "result a + b + c" and haven't been able to overcome this.
I appreciate any advice and thank you for reading this post. I also apologize if this question has been broached before.
Thank you
March 24th, 2013, 03:26 PM
-
Using parseInt is the correct approach.
PHP FAQ
Originally Posted by Spad
Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around