此JavaScript代碼運行成功,但我認爲它不會通過它的「其他」語句,因爲它不打印它的控制檯...爲什麼?或條件從未評估爲真
i = 0;
for(var i=1; i<4; i++) {
var crazy = prompt("would you marry me?");
if(crazy === "Yes"|| "yes") {
console.log("hell ya!");
}
/* when it asks "will you marry me" and if the user says either "No" or "no", it does't print "ok..I'' try again next time". instead, it still says "hell ya !" */
else if (crazy ==="No" ||"no") {
console.log("ok..I'll try again next time !");
}
}
var love = false;
do {
console.log("nonetheless, I LOVE YOU !");
}
while(love);
條件的語法不正確。你需要再次檢查變量。 '瘋狂==='是'||瘋狂==='yes'' –
它應該是'瘋狂===「是」||瘋狂===「是」。'||'yes''不是_compared_,而是評估爲'true'。 – Xufox
嘿,非常感謝這麼多傢伙! –