gpt4 book ai didi

javascript - 为什么我的开关列表中只有第一种情况可以正常工作?

转载 作者:行者123 更新时间:2023-11-28 19:22:09 27 4
gpt4 key购买 nike

对于我的生活,我无法弄清楚它出了什么问题。当我运行这个脚本时,第一个“STAY”案例工作得很好。运行任何其他情况都会出现错误(未定义不是函数)。

通过我的 JS 检查器运行它,看起来没问题。谷歌搜索了一下,我看到有同样问题的其他人都被告知他们的休息时间要么使用不正确,要么不存在。根据我所学到的,所有语法对我来说都是正确的。将其与示例“游戏”进行比较,看起来与他们的做法非常相似。我究竟做错了什么?!感谢您的帮助

var user = prompt("You see God. Do you want to STAY, PUNCH HIM, or CRY?").toUpperCase();

switch(user) {
case 'STAY':
var curious = prompt("Are you a curious person?").toUpperCase();
var insight = prompt("Are you an insightful person?").toUpperCase();
if (curious === "YES" && insight === "YES") {
console.log("Maybe it was a good idea to stay and speak to him");
} else if (curious === "YES" || insight === "YES") {
console.log("Well, maybe you can scrunge up something to say");
} else {
console.log("Why would you stay if you have nothing intelligent to say?");
}
break;
case 'PUNCH HIM':
var strong = prompt("Are you ridiculously stronger than God?").toUpperCase();
var fast = prompt("Are you faster than a minute man?").toUpperCase();
if (strong === "YES" && fast === "YES") {
console.prompt("You still dead, but not as dead as you would've been");
} else if (strong === "YES" || fast === "YES") {
console.prompt("One ain't good enough, homie");
} else {
console.prompt("Slow and weak? Bad choice, dag");
}
break;
case 'CRY':
var convincing = prompt("Are you superbly convincing with crying?").toUpperCase();
var female = prompt("Are you a female?").toUpperCase();
if (convincing === "YES" && female === "YES") {
console.prompt("You'll prolly be ok, boo");
} else if (convincing === "YES" || female === "YES") {
console.prompt("Hope you're a female");
} else {
console.prompt("You dead!");
}
break;
default:
console.prompt("Answer the question with the supplied answers");

}

最佳答案

使用console.log而不是console.prompt

关于javascript - 为什么我的开关列表中只有第一种情况可以正常工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28642657/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com