let q;
while ((q !== "yes")||(q !== "no")) {
q = prompt("yes or no?");
}
我已经试过了,但我不明白为什么它不起作用,因为:
while (q !== "yes") {
q = prompt("yes or no?");
}
有效。
最佳答案
呃,看来你用过
while ((q !== "yes")||(q !== "no"))
这将始终转换为 true
,因为 q 不能同时为“yes”和“no”,它将始终计算为 true。条件应该是应该是
while ((q !== "yes") && (q !== "no"))
关于javascript - 我正在尝试创建一个提示用户 "enter yes or no to exit"的 JavaScript 程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58478644/