gpt4 book ai didi

javascript - 或者条件永远不会计算为 true

转载 作者:行者123 更新时间:2023-12-03 10:17:11 26 4
gpt4 key购买 nike

这段 JavaScript 代码成功运行,但我认为它没有通过“else”语句,因为它没有打印其控制台......为什么?

 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);

最佳答案

尝试这样的事情,

 if(crazy.toUpperCase() === "YES") {
console.log("hell ya!");
}

关于javascript - 或者条件永远不会计算为 true,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29811872/

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