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 Loops, Arrays and Objects Simplify Repetitive Tasks with Loops `do ... while` Loops

My 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

I 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.

Thank you for your quick response!

Glad to help!

A 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.

Not 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).

Thank you for your quick response!