我写了一个JavaScript计算器...但是当我将第一个数字设为
请问有人能帮我吗?当我尝试将这两个数字相减时也会发生这种情况。为什么会这样呢?
2
,第二个数字设为3
时,结果显示为23
,但我想要将这两个数字相加。请问有人能帮我吗?当我尝试将这两个数字相减时也会发生这种情况。为什么会这样呢?
var cal = prompt("Please enter what type of calculation you want to do\n
if you wanna add enter = 1\n
if you want to minus enter = 2\n
if you want to divide enter = 3\n
if you want to multiply enter = 4");
if (cal == 1) {
var a = prompt("Please enter your first number");
var b = prompt("please enter your second number");
alert("The result is , " + a+b);
}
if (cal == 2) {
var c = prompt("Please enter your first number");
var d = prompt("please enter your second number");
alert("the result is , " + c - d);
}
parseInt()
将它们转换为整数值。 - Dipesh Parmar