2 回答

TA貢獻1804條經驗 獲得超2個贊
您應該刪除它getText,它將正常工作:
var day = prompt('Enter a day of the week.');
console.log('Day is: ' + day);
if (day == 'Sunday' || day == 'Saturday') {
console.log("It's the weekend!");
} else {
console.log("Can't wait for the weekend to get here.");
}

TA貢獻1828條經驗 獲得超6個贊
如果用戶單擊“確定”或單擊“取消”,該prompt()函數始終返回 a 。在您的情況下,只要您輸入一些內容并單擊“確定”,就會出現一個字符串,可能是或。stringnullday"Sunday""Saturday"
但是,如果您希望將大寫字母和小寫字母視為相同,例如"sunday"相當于"Sunday",則應使用toLowerCase()ortoUpperCase()方法來確保兩個字符串要么全部小寫,要么全部大寫。像下面這樣:
var day = prompt("Enter a day of the week.");
console.log("Day is: " + day);
//if user input is equal to Sunday OR user input is equal to Saturday,
if (day.toLowerCase() == "sunday" || day.toLowerCase() == "saturday") {
console.log("It's the weekend!");
} else {
console.log("Can't wait for the weekend to get here.");
}
添加回答
舉報