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 trialJohn Silverstein
6,290 PointsAlternative way to define the condition that makes the while loop stop?
Just want a clarification I understand the while condition defined as "! correctguess" practically means - "as long as correctguess is false". But is there a different, more intuitive, way to state that condition? would simply stating: "correctguess=false" change the variable's value to false again? and how about typing it like this: "correctguess!==false" - is that meant only for numbers?
1 Answer
Steven Parker
231,275 PointsYes, you could write "correctguess !== false
".
But that's the opposite test from what you wrote the first time. The test "! correctguess
" would actually be the same thing (logically) as "correctguess !== true
" or "correctguess === false
". But if correctguess is a boolean (something that is either true or false) the way you wrote it the first time would be preferred.
And yes, "correctguess = false;
" is an assignment, and would set the variable's value to false.
John Silverstein
6,290 PointsThanks!. Yeah, I did mean "correctguess !== true" as in "not identically equals true". But you say the "! correctguess" is preferred? why is that? I'm just thinking not to adopt this confusing type of defining a condition, and stick to the !==
Steven Parker
231,275 PointsA boolean (like correctguess) already represents either true or false, so it can stand by itself (negated with "!" if needed) as a condition. Comparison operators are generally used on other types to produce a boolean result.
Vlad Legkowski
9,882 PointsVlad Legkowski
9,882 PointsI understand it this way - the stuff in the parenthesis "(...)" should evaluate to
true
.This is hard one for me to explain, but I want to try:
So, what you propose above, you want to evaluate "is it true that something is false?" -
(correctguess=false)
, if yes run the code bellow.While standard practice is "is something is not true?" -
(!correctguess)
, if yes run the code bellow.!==
, read here https://www.quora.com/What-does-the-operator-mean