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 JavaScript Basics (Retired) Making Decisions with Conditional Statements Boolean Values

Can someone explain in more depth as to why he is able to put false and it reads the else statement

I do not get the concept as it is not really explained

2 Answers

Mohammed Khalil Ait Brahim
Mohammed Khalil Ait Brahim
9,539 Points

Well The thing is in an if else block the if block is only executed if the condition it holds evaluates to true so if the condition evaluates to false which is the case here we go directly to execute the statements in else block

if( true ) {
 // EXECUTE THIS
}
else {
 // THIS WILL NOT BE EXECUTED
}

if( false ) {
 // THIS WILL NOT EXECUTE
}
else {
 // EXECUTE THIS
}

thank you ... that is what I was looking for

Sometimes you just gotta go forward in the teaching to see how and why things are used.

that was so helpful ,, thanks Mohammed

Adam Oliver
Adam Oliver
8,214 Points

correctGuess must = something. You assign it false by default, that way it can only be changed to true if the player guesses correctly. ELSE it stays as it was (false).