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 trialBrian Prouty
1,792 PointsWhy is the if (correctGuess) at the end is equal to true?
I am wondering why when you call the if (correctGuess) later in the code why is that not equivalent to correctGuess = false; at the top? I was under the impression that the only way to call 'correctGuess = true' is either typing it out like that or '(! correctGuess)'... can anyone help explain this??
Brian Prouty
1,792 Pointsi just linked it in the question :)
3 Answers
Steven Parker
231,275 PointsThe assignment on line 15 changes the value of "correctGuess" to "true'. That's what happens when the number guessed matches the random number.
The only way for "correctGuess" to still be false at the end is if the loop ends because the count got to 10 and a match was never entered.
Victor Warner
1,882 Pointsif you dont set correct guess to false does that mean later on a conditional statement will assing a boolean value to it?
Steven Parker
231,275 PointsIt is set to "false" to begin with because it might not get set later on.
Test1 RET
8,913 PointsI am agree with Brian, if the break is present, now the correctGuess variable is useless... am I wrong?
Steven Parker
231,275 PointsNo, it indicates if the loop ended from running out of turns (false) or because the right answer was given (true).
KRIS NIKOLAISEN
54,972 PointsKRIS NIKOLAISEN
54,972 PointsCan you post code? I don't see what you are talking about in the video workspace.