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.");
}
添加回答
举报