Javascript numbers concatenate instead of adding but typeof is number not string

前端 未结 5 1452
执念已碎
执念已碎 2021-01-02 04:49

I am new to javaScript. I am building a calculator here

I have stored the input values in variables so that I can eventually manipulate the results to perform calcul

5条回答
  •  失恋的感觉
    2021-01-02 05:17

    You're concatenating the strings with + and then you're converting that concatenated result to an int.

    You want to convert to an integer before you add. Something like:

    var theTerm = parseInt($("#theTerm").val(), 10);
    ...
    var theResult = theTerm + theRate + thePrice + theTax + theDown + theTrade;
    

提交回复
热议问题