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 trial
Nouh Ahmed
7,085 PointsguessCount
Why put guesCount right after prompt inside the do. What about if i put it inside the if part of the do while loop. Will it work like this:
do { guess = prompt("I'm thing of a number from 1 to 10"); if (parseInt(guess) === randomNumber) { guessCount += 1; // I put the guesCount inside the if part correctGues = true; } while (! correctGues);
1 Answer
Steven Parker
243,656 Points
You won't get a correct count of tries that way.
Incrementing the count inside the test for a correct value will cause only a correct guess to be counted, so the result displayed at the end will always be "1".
The original intention was to count all guesses and display the total when the correct guess was given.
Nouh Ahmed
7,085 PointsNouh Ahmed
7,085 PointsThanks.