Hello,
var a = 1;
var b = 2;
var c = a+b;
c will show as 12; but I need 3
How do I do it using JavaScript?
Thanks Jean
Hello,
var a = 1;
var b = 2;
var c = a+b;
c will show as 12; but I need 3
How do I do it using JavaScript?
Thanks Jean
It looks like you have strings and not numbers, you need parseInt() or prseFloat() (if they may be decimals) here, like this:
var a = "1";
var b = "2";
var c = parseInt(a, 10) + parseInt(b, 10);
//or: var c = parseFloat(a) + parseFloat(b);
You can test the difference here, it's worth noting these are not jQuery but base JavaScript functions, so this isn't dependent on the jQuery library in any way.