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 trialNatalia Karolinskaya
9,367 PointsWhy do we assign 'false' to correctGuess?
I mean we could assign 'true' from the start?
2 Answers
Julian Gutierrez
19,201 PointsIn this program you are checking to see if the user's inputted guess is correct. correctGuess shouldn't initially be true because then any number the user inputs would evaluate to a "correct answer."
John Murphy
1,122 PointsI am not sure what it is you're working on, but generally where a boolean such as "correctGuess" comes up its to validate some input to determine the next sequence of events in the program.
If we were to initialize the value of "correctGuess" to "true", it would assume that any input is "correct" and follow that sequence of events - which is obviously not good. I have an example of this being used in a simple Hangman Java app that I did for a college project that you can see below if you like.
In my case, it was used to determine whether or not the users guessed letter was a match. If so, correctGuess = true - which then updated the statistics and proceed to the next task.
Jason Anders
Treehouse Moderator 145,860 PointsJason Anders
Treehouse Moderator 145,860 PointsThat's correct, and I misread the question. :) Too early in the morning for me, I guess.