嘿,我做了一个JavaScript计算器并想试试5 + 5,它给我55而不是10?然而,如果我尝试5/5,它给我1,如果尝试5-5,它给我0,乘法也是一样的。我不明白我的代码有什么问题,还想尝试console.log,但它不起作用,所以我使用document.write。
这是我的代码:
var Plus = function()
{
var N1 = prompt("Enter first number");
var N2 = prompt("Enter second number");
var sum = (N1 + N2);
document.write(sum);
}
var Minus = function()
{
var N1 = prompt("Enter first number");
var N2 = prompt("Enter second number");
var sum = (N1 - N2);
document.write(sum);
}
var Division = function()
{
var N1 = prompt("Enter first number");
var N2 = prompt("Enter second number");
var sum = (N1 / N2);
document.write(sum);
}
var Times = function()
{
var N1 = prompt("Enter first number");
var N2 = prompt("Enter second number");
var sum = (N1 * N2);
document.write(sum);
}
var Answer = prompt("Plus ?, Minus ?, Division ? or Times ?");
if( Answer === "Plus")
{
Plus();
}
else
{
if( Answer === "Minus")
{
Minus();
}
else
{
if( Answer === "Division")
{
Division();
}
else
{
if( Answer === "Times")
{
Times();
}
else
{
document.write("How did you get here?");
}
}
}
}