小编Bra*_*dez的帖子

谁能解释为什么这段代码连接而不是添加数值?

所以,首先,我知道这段代码很乱,请耐心等待,但谁能解释为什么这会一直连接输入的信息而不是在传递后添加数值parseInt()

var sol = 0;
var n = 0;

while(n !== null)
{

parseInt(n = prompt("Please enter a number to be added onto stack"));
  if(n != null || n != NaN)
  {
    sol = parseInt(sol);
    sol += n;
  }

}
console.log(sol);
Run Code Online (Sandbox Code Playgroud)

javascript concatenation addition parseint

3
推荐指数
1
解决办法
36
查看次数

标签 统计

addition ×1

concatenation ×1

javascript ×1

parseint ×1