gpt4 book ai didi

Javascript - while 循环不显示成功选项

转载 作者:行者123 更新时间:2023-11-30 16:46:01 24 4
gpt4 key购买 nike

为什么我的代码从不提示“be happy”?

它适用于所有其他选项,但不适用于此选项。为什么会这样?

var i = "";
while (i != "YES"){
if(i == "NO"){
alert("You should be!");
}

else if(i == "YES") {
alert("Be happy!")
}

else{
if(i == ""){
}
else {
alert("C'mon dude... Answer simply yes or no!");
}
}

i = prompt("Are You happy?").toUpperCase();
}

最佳答案

因为当你进入循环时,条件只是确保 i 在循环开始时永远不会是 'Yes'

i = prompt("Are You happy?").toUpperCase(); 拉到循环的开头。

关于Javascript - while 循环不显示成功选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31229243/

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