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 trialGeovani Mejia
Front End Web Development Techdegree Student 7,940 PointsWhy we start the game with var correctGuess = false; thanks
I understand the definition of Boolean, but I don't understand why we started the game demo with var correctGuess = false;
Why did we set correctGuess variable to false but not to true in the beginning? thanks
1 Answer
Jamie Reardon
Treehouse Project ReviewerBecause later in the program, it will check by using an if condition to test if the player has got the right guess. If the player has the right guess, then the program will update correctGuess to true. The true value will be tested in another if condition later in the program to tell the player that they won the game if the condition is true.
At the start of the game, the player hasn't correctly guessed the number so the program predicts that to be false, and you will be instructing the program to check if the player has correctly guessed it later on in the game, so you will set it to false at the start of the game.
Geovani Mejia
Front End Web Development Techdegree Student 7,940 PointsGeovani Mejia
Front End Web Development Techdegree Student 7,940 PointsThanks Jamie!
Jamie Reardon
Treehouse Project ReviewerJamie Reardon
Treehouse Project ReviewerYou are welcome!