我正在製作一個簡單的JS計算器。但是,變量中的提示不會出現。是的,我會將孩子的功能改變成變量,以使開關語句成爲可能。但即使將它打成JS固定器,它也不起作用。任何人都可以告訴我該怎麼做?我有點卡在這裏。我曾嘗試把它放入JSFiddle,但它仍然沒有奏效。謝謝,如果我得到答案!我的提示代碼不起作用
var firstNumber = prompt("Type in the first number that you want to add,subtract,divide,multiply,power(square or to the power of) or square root.");
var operationForNumber() = prompt("Type in the symbol that matches the operation that you want to use(2 for square, ! for square root, /,for division and a * for multiplication).");
var secondNumber() = prompt("Type in the second number that you want to add,subtract,divide,multiply,square or square root.");
switch (operationForNumber) {
case +:
firstNumber "+"
secondNumber
break;
case -:
firstNumber "-"
secondNumber
break;
case /:
firstNumber "/"
secondNumber
case *:
firstNumber "*"
secondNumber
break;
case 2:
Math.pow(firstNumber, secondNumber);
break;
case !:
sqrt(firstNumber)
default:
console.log("The number you have typed is too great to be calculated or the operation that you chose(+,/,-,X) isn't valid!");
}
用引號括起你的操作符,否則你有語法錯誤 – DarkBee
運算符在+, - 等? – DudeManPerson
您需要在環境中看到語法錯誤,因爲它們太多(缺少變量,不存在的函數等等) –