我写了一个 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);
}