Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript True or False Statements … Reply To: True or False Statements …

#158668
__
Participant

Perhaps you could explain a scenario where a developer would want the … if … statement to be false and the … else … to be true …

It’s not an issue of “wanting” the if to be true or false, it’s an issue of knowing if it is true or false.

if( userSaidTurnLeft ){
    turnLeft();
}
else{
    turnRight();
}

I don’t care which way they turn, I just need to know what their choice was.

when an if / else is set up … the statement immediately after … in this case … Welcome … is always True … and the preceding statement … Dont let the door hit ya … is always False. Right?

I’m not sure I follow your question.

As @TheDoc answered, If the if is true, then the if block will be executed. If it’s false, the else block will execute.

However, in your original example, the if condition is not true. Watch out for that door.

(Also, just to make sure we are not misunderstanding, the else is not the “preceding” statement; it is the following statement.)