尝试使用函数在 JavaScript 中添加三个数字,但它没有添加它们,而是只是将它们写为一个数字
function numinput(a,b,c,res){
a = prompt("Enter first number");
b = prompt("Enter second number");
c = prompt("Enter third number");
res = a + b + c ;
alert (res);
}
numinput();
最佳答案
使用
将值转换为数字parseInt
。这是一个有效的解决方案。
function numinput(a,b,c,res){
a = parseInt(prompt("Enter first number"), 10);
b = parseInt(prompt("Enter second number"), 10);
c = parseInt(prompt("Enter third number"), 10);
res = a + b + c ;
alert (res);
}
numinput();
关于javascript - 尝试使用函数在 javascript 中添加三个数字,但它没有添加它们,而是只是将它们写为一个数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43563383/