-2
當我通過chrome中的html頁面運行此代碼並放入,例如number1 = 1000和number2得到2000時,它警告1000更大。爲什麼?在JavaScript中,爲什麼我的「<" and ">」比較被顛倒?
var number1 = prompt("Pick a number");
var number2 = prompt("Pick another number");
if (number1 < number2) {
alert(number1 + "is bigger!");
} else if (number2 < number1) {
alert(number2 + "is bigger!");
} else if (number1 == number2) {
alert(number1 + "is equal to" + number2)
}
您提醒錯誤信息'x
@PaulS。這確實是問題的一半。 :-) –
我道歉,我暫時扭轉了比較符號。他們原本是: var number1 = prompt(「Pick a number」); var number2 = prompt(「Pick another number」); if(number1> number2){ \t alert(number1 +「is greater!」); (number2> number1){ \t alert(number2 +「is greater!」); else if(number2> number1){ } (number1 == number2){ \t alert(number1 +「等於」+ number2) } ......並且它仍然向後報警。 – MattP