rossmclenny
rossmclenny

Reputation: 37

If statement ignores number value

Apologies for being so inept!

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`);
}

Here whatever i make the variable of population to be it seems to be ignored by the If statement and im not sure why!

Upvotes: 0

Views: 81

Answers (3)

eric anthony
eric anthony

Reputation: 71

You could use and (&&) operator for that

if (language === "English" && population < 50 && isIsland === false) {
console.log(`You should live in ${country} :)`);
} else {
console.log(`${country} does not meet your criteria`);
}

Upvotes: 0

Xin
Xin

Reputation: 36490

"or" condition:

if (language === "English" || population < 50 || isIsland === false)

"and" condition

if (language === "English" && population < 50 && isIsland === false)

Upvotes: 0

phi-rakib
phi-rakib

Reputation: 3302

You are missing logical operator in if statement. Logical operators are use to test for true or false. There are three logical operators in JavaScript.

  • And(&&)
  • or(||)
  • not(!)

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`);
}

Upvotes: 1

Related Questions