{"id":10196677,"date":"2018-04-19T03:27:09","date_gmt":"2018-04-19T03:27:09","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/javascript-addition-not-working\/"},"modified":"2018-04-19T03:27:09","modified_gmt":"2018-04-19T03:27:09","slug":"javascript-addition-not-working","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/javascript-addition-not-working\/","title":{"rendered":"Javascript Addition Not Working"},"content":{"rendered":"<p>This is probably has a simple answer but I have been working on this for hours without being able to figure it out.  I have the following function that retrieves a value &#8216;spot&#8217; from input field &#8216;myInput&#8217; and calculates a value &#8216;tmpspot&#8217;.<\/p>\n<p>For this example I am entering the number &#8217;23&#8217; in the field &#8220;myInput&#8221; (type=&#8221;number&#8221;).  When I pass &#8217;23&#8217; to the function as shown below the function properly returns &#8217;44&#8217;.  However, when I comment out the line &#8220;tmpspot = tmpspot &#8211; (0 &#8211; spot) ;&#8221; and instead use the previous line &#8220;tmpspot = tmpspot + spot ;&#8221;, the function returns &#8216;2123&#8217;, as though it concatenated the two numbers instead of adding them together.<\/p>\n<p>What am I missing?<\/p>\n<p>function NextSpot() {<br \/>\n  var spot = document.getElementById(&#8220;myInput&#8221;).value;<br \/>\n  var tmpspot = spot % 2 ;<br \/>\n  tmpspot = (tmpspot &#8211; (0 &#8211; spot)) &#8211; 1 ;<br \/>\n  tmpspot = 65 &#8211; spot ;<br \/>\n  tmpspot = tmpspot \/ 2 ;<br \/>\n  tmpspot = parseInt(tmpspot);<br \/>\n\/\/  tmpspot = tmpspot + spot ;<br \/>\n  tmpspot = tmpspot &#8211; (0 &#8211; spot) ;<br \/>\n  document.getElementById(&#8220;demo&#8221;).innerHTML = tmpspot ;<br \/>\n  return true ;<br \/>\n}<\/p>\n","protected":false},"template":"","class_list":["post-10196677","topic","type-topic","status-publish","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/10196677","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/10196677\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=10196677"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}