为如此无能而道歉!let country = "UK";let language = "English";let population = 60;let isIsland = false;if (language === "English", population < 50, isIsland === false) {console.log(`You should live in ${country} :)`);} else {console.log(`${country} does not meet your criteria`);}在这里,无论我将 population 变量设置为什么,它似乎都被 If 语句忽略了,我不确定为什么!
3 回答
慕娘9325324
TA贡献1783条经验 获得超4个赞
您在 if 语句中缺少逻辑运算符。逻辑运算符用于测试真或假。JavaScript 中有三个逻辑运算符。
和(&&)
或(||)
不是(!)
let country = "UK";
let language = "English";
let population = 60;
let isIsland = false;
if (language === "English" && population < 50 && isIsland === false) {
console.log(`You should live in ${country} :)`);
} else {
console.log(`${country} does not meet your criteria`);
}
白衣染霜花
TA贡献1796条经验 获得超10个赞
“或”条件:
if (language === "English" || population < 50 || isIsland === false)
“和”条件
if (language === "English" && population < 50 && isIsland === false)
胡子哥哥
TA贡献1825条经验 获得超6个赞
您可以为此使用 and (&&) 运算符
if (language === "English" && population < 50 && isIsland === false) {
console.log(`You should live in ${country} :)`);
} else {
console.log(`${country} does not meet your criteria`);
}
添加回答
举报
0/150
提交
取消