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 trialJoshua Swilling
1,135 Pointsdo-while loop
I am curious and want to ask, can any operator be used to test conditions within the " while( ____ )" half of the loop?
2 Answers
Juan Naputi
1,772 PointsYup! All of the conditional operators (===, !==, >, <, >=, <=) are valid inside of the "while()" half of the loop.
Juan Naputi
1,772 PointsFor while ( !== correctGuess)
, you have to provide a value that you want to compare. Typical setup would be: while ([!] {variableToCheck} {comparisonOperator} {valueToCheckAgainst})
. With this template, you are missing the {variableToCheck} part of your while-loop.
For the second one, while (guess ! correctGuess)
, you have to use one of the valid comparison operators (===, !==, ==, !=, >=, <=). If you don't have these, it is an invalid comparison. The only time you will be using an not [!] comparison on its own is if you are looking for a false boolean value: while ( !isTrue )
.
I can expand the context if needed.
Hope that helps!
*** For the first answer, the [!] at the front means that it is optional and is used when you are checking for a false boolean value. Refer to the second answer for a reference.
Andrew Baran
Courses Plus Student 5,139 PointsThanks Juan. I appreciate your help!
Andrew Baran
Courses Plus Student 5,139 PointsAndrew Baran
Courses Plus Student 5,139 PointsCan you tell me how come this doesn't work? while ( !== correctGuess)
and why this doesn't work either?
while ( guess ! correctGuess)
Thank you