If 语句忽略数字值

为如此无能而道歉!


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 语句忽略了,我不确定为什么!


慕盖茨4494581
浏览 197回答 3
3回答

慕娘9325324

您在 if 语句中缺少逻辑运算符。逻辑运算符用于测试真或假。JavaScript 中有三个逻辑运算符。和(&&)或(||)不是(!)let country = "UK";let language = "English";let population = 60;let isIsland = false;if (language === "English" && population < 50 && isIsland === false) {&nbsp; console.log(`You should live in ${country} :)`);} else {&nbsp; console.log(`${country} does not meet your criteria`);}

白衣染霜花

“或”条件:if&nbsp;(language&nbsp;===&nbsp;"English"&nbsp;||&nbsp;population&nbsp;<&nbsp;50&nbsp;||&nbsp;isIsland&nbsp;===&nbsp;false)“和”条件if&nbsp;(language&nbsp;===&nbsp;"English"&nbsp;&&&nbsp;population&nbsp;<&nbsp;50&nbsp;&&&nbsp;isIsland&nbsp;===&nbsp;false)

胡子哥哥

您可以为此使用 and (&&) 运算符if (language === "English" && population < 50 && isIsland === false) {console.log(`You should live in ${country} :)`);} else {console.log(`${country} does not meet your criteria`);}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript