cannot use + when try to add number

后端 未结 4 1428
日久生厌
日久生厌 2020-11-30 15:06

After i selected option 1 and after i add the number like 100 it results like this 100100

This is the code:

var userAmount;
    var userMoney = 100;
         


        
4条回答
  •  攒了一身酷
    2020-11-30 15:26

    That's because the user given number is actually a string.

    A quick way to fix it is to type:

    var totalMoney = userMoney + userAmount * 1;
    

提交回复
热议问题