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 trialEric Araujo-Martínez
4,011 Pointsif the computer guesses the correct number at first attempt, does it mean our counter remains in zero?
I mean, if the loop condition if evaluated first and it is false from the very begining, braking the loop, then if the computer gets the correct number in the first attemp the counter never goes to 1 and in the document write it says "0 attemps"?.
1 Answer
jsdevtom
16,963 PointsAt 5:00 in the video, Dave says "The guess variable doesn't have any value. So when we first get to the loop the JavaScript interpreter evaluates this condition. Does guess not equal random number? Why, yes. Because guess has no value, and it doesn't match random number. So, we enter the loop and we guess."
This basically means that it is impossible for the loop to guess the number on the first attempt because guess is not yet assigned a value. So to answer your question: our counter can not remain in zero.
:-)
Eric Araujo-Martínez
4,011 PointsEric Araujo-Martínez
4,011 PointsThanks a lot.
jsdevtom
16,963 Pointsjsdevtom
16,963 PointsGlad I could help