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 trialKaleshe Alleyne-Vassel
8,466 PointsDo booleans and conditional statements have an ingrained relationship? else for true, elseif for false?
You are able to put else (variable) {} without stating whether it is true or false, it just knows that it should be true in order to not have to go through to the else if code. While I understand it, it also confused me. How are you able to leave out the information, unless the relationships is predetermined in a way
2 Answers
Jennifer Nordell
Treehouse TeacherKaleshe Alleyne-Vassel Hi there! I think you might be referring to if(correctGuess)
that is shown around 1:09 in the video. Every variable has an inherent "truthiness" to it. The variable correctGuess
will evaluate as true
(but not explicitly equal to true) if it is not evaluated as "falsy". Things like null, undefined, an empty string and 0 are considered "falsy" and will evaluate to false. Non-zero numbers, strings that aren't empty and more evaluate to "true".
For more examples of things that are "truthy" and "falsy", I recommend looking at the MDN documentation for falsy and truthy
So the if(correctGuess)
is saying if the value stored in correctGuess
is not false
, 0, null, undefined or NaN, then do the following code.
Hope this helps!
Kaleshe Alleyne-Vassel
8,466 PointsThanks, this helps a lot!
Kaleshe Alleyne-Vassel
8,466 PointsSorry, the question wasn't really targeted primarily at this video. But to this video and a challenge beforehand. Though, I now understand it!
Alexander Davison
65,469 PointsAlexander Davison
65,469 PointsHello Kaleshe,
Where are you in the video? It would help to tell where you are in the video e.x. 3:13 meaning three minutes and thirteen seconds in