cannot use + when try to add number

后端 未结 4 1430
日久生厌
日久生厌 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:29

    You need to cast your values to integers first. Try using parseInt()

    change:

    var totalMoney = userMoney + userAmount;
    

    to this:

    var totalMoney = parseInt(userMoney, 10) + parseInt(userAmount, 10);
    

提交回复
热议问题