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 trialJoel Camacho
2,355 PointsNot sure I get the point of using a "flag" here.
Hi,
I'm not entirely clear on the purpose of using a "correctGuess" flag to break out of the loop. Can't the while loop be what is testing the condition of "guess" being equal or not to randomNumber? Here's what I have, and it seems to run fine:
do { guess = prompt("I am thinking of a number between 1 and 10. What is it?"); guessCount += 1;
} while ( parseInt(guess) !== randomNumber )
Am I missing something?
Thank you in advance for your response.
1 Answer
alastair cooper
30,617 PointsIt would make the code more readable at first glance. Whilst your code is more compact, and would execute a few nanoseconds quicker, it is slightly more difficult to immediately understand what it does (admittedly, not much more difficult!).
Joel Camacho
2,355 PointsJoel Camacho
2,355 PointsSorry, this should have been posted under the next video, not this one.