我正在尝试做的是一个循环,提示用户输入信息,并且仅在输入某些字符串后才会停止。具体来说,我只希望它接受某些字母,包括大写和小写字母。这是我到目前为止的内容:

 do
 {
  salesP = prompt("Enter the initial of the first name of the salesperson: ", "");
 }while (salesP != "C" || salesP != "c")


基本上,while部分是完全错误的,我知道。我已经尝试了所有我能想到的东西,而我能做的最好的事情就是让它接受单个变量。我还需要它接受d,x和m两种情况。

最佳答案

该代码几乎是正确的。您只是在while语句中使用了错误的布尔运算符。您正在使用OR(||),而应使用AND(&&)。

所以:

 do
 {
  salesP = prompt("Enter the initial of the first name of the salesperson: ", "");
 }while (salesP != "C" && salesP != "c")

10-08 02:11