Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

how to run the if statement

var a= 2;

if(a===2 && a==3 && a==4){

console.log("ok");

}

//how can i run this if statement help me figure out this problem

2 Answers

You need to add an else statement to specify a block of code to be executed if the condition is false.

else {
   console.log("notok");
}

The if statment wont run because the var a cant be 3 diffrent values. So if a = 2, a cant be 2 and 3 and 4 at the same time.

You can use ||(or) instead of &&(and) it would give out the ok. Or like Rachel sayed use an else to at least give out anything.

- Also why do you check in the first statment (a===2) if the types are also the same and then you simplie check if for example b == 3 (here does the string "3" pass as well)

You could also check 3 diffrent values like

if(a === 2 && b == 3 && c == 5)