Search code examples
javascriptconditional-statements

Javascript: How can I chain conditionals?


Can you help me with this?

x = 2 + 2;
y = 1 + 3;

a = 5 + 5;
b = 7 + 3;

///How can I do this: 
if (x == 4 && y == 4 and a == 10 && b == 10) {
  console.log("you are correct!");
}

///Instead of this: 
if (x == 4 && y == 4) {
  console.log("you are correct!");
}

if (a == 10 && y == 10) {
  console.log("you are correct!");
}

Solution

  • Do it like this

    if((x == 4 && y == 4) || (a == 10 && b == 10)){
        console.log("you are correct!")
    }