當我運行這個腳本時,它停留在提示用戶輸入第一個數字。它似乎不會數x。Javascript loop stuck
function doMath() {
for (var x = 1; x < 3; x = x + 1) {
var var1;
var var2;
var var2;
var num;
if (x = 1) {
var num = prompt("Enter first number please");
var1 = parseInt(num)
}
else if (x = 2) {
var num = prompt("Enter second number please");
var2 = parseInt(num)
}
else {
var num = prompt("Enter third number please");
var3 = parseInt(num)
return Math.min(var1, var2, var3);
}
}
}
您使用賦值操作符,而不是比較的。將'if(x = 1)'更改爲'if(x === 1)'等等 – Phil