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 trialJessica Evans
7,372 PointsMy while loop is different from the video, but it still works. Could my method cause problems in the future?
I got ahead of the video for a moment and entered my while loop like:
while (correctGuess !== true)
In the vid he uses:
while ( ! correctGuess )
The rest of the code is the same and it works the same as in the video when I preview it. Could my way cause problems/in other situations?
2 Answers
Philip G
14,600 PointsI don't think so, because its actually the same.
!== true equals false
! equals false
But for better readability, you should use the method from the video.
Gabriel D. Celery
13,810 PointsNot really. The while() loop runs until whatever you put between the braces stays true.
The (correctGuess !== true) checks whether the current state of correctGuess is not equal to true and returns a boolean value (true or false).
The ( ! correctGuess ) simply sets the current state of correctGuess to the opposite (true->false or false->true).
Jessica Evans
7,372 PointsThank you for your quick response!
Jessica Evans
7,372 PointsJessica Evans
7,372 PointsThank you for your quick response!
Philip G
14,600 PointsPhilip G
14,600 PointsGlad to help!
Gabriel D. Celery
13,810 PointsGabriel D. Celery
13,810 PointsA minor addition to what Philip said. Those statements return false the moment when you are making a right guess thus stopping the loop. While you are guessing (wrongly) the statement returns true.
I am telling this, because the answer "!== true equals false" and "! equals false" can be interpreted the wrong way.