View Full Version : +=
07-29-2011, 07:22 PM
how can you make a += work so if you add 5+5 with += it would come out as 55 how would you make it come out as 10?
07-29-2011, 10:59 PM
It will automatically come out as 10 if you make sure that both sides of the "+=" are numeric values. If you (for example) read the value of an input box, it will always be a string (even if you entered a number). You'll have to convert it into a numeric value before adding 5 to it
var myValue = document.getElementById('myinput').value;
myValue = Number(myValue); // convert it to a numeric value if possible, otherwise it will be "NaN"
myValue += 5; // mathematically add 5 to this value
07-29-2011, 11:09 PM
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.