【发布时间】:2019-10-08 01:49:18
【问题描述】:
如果用户输入了特定的符号或字符串,我想启动一个代码。 在此任务中,我需要检查用户是否输入了以下任何内容:“a”、“b”、“c”、“d”。然而,它似乎只是忽略了 if 语句。
这是整个问题: 编写一个程序,根据其标签和等级确定棋盘方块的颜色。 输入:在第一行,您将收到 L - 标签 在第二行,您将收到 R - 排名
let L = prompt();
let R = Number(prompt());
if (L == ("a", "c", "e", "g")) {
if (R % 2 == 0) {
/*if we are on a/c/e/g lines and the number is even the
square is white*/
console.log("light");
} else {
console.log("dark");
} //else it is going to be odd therefore dark
} else if (L == ("b", "d", "f", "h")) { //opposite logic:
if (R % 2 == 0) {
console.log("dark");
} else {
console.log("light");
}
}
问题是我不知道如何比较这两个字符串。我尝试了一些字符串方法,但我想我只是犯了一个 sintax 错误
【问题讨论】:
标签: javascript