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 trialrachaelallison
9,521 Pointswhere is the code for the computer to guess t he random number?
I see in this video code to create a random number, and code to evaluate whether the computer guessed correctly, but it seems to be missing a part in the middle. In which part of this code does the computer guess the random number?
thanks everyone!
1 Answer
Jason Anello
Courses Plus Student 94,610 PointsHi Rachael,
That's close but the while loop isn't producing 2 random numbers, it's only producing the computer guess which is stored in the variable guess
On line 2 is where the first random number is generated. This is the secret number that the computer needs to guess and it's stored in the variable randomNumber
This value doesn't change throughout the rest of the program.
The while loop is then used to continually generate new guesses until it matches the secret number in randomNumber
Then the program ends after displaying some results.
rachaelallison
9,521 Pointsrachaelallison
9,521 Pointsok, as I'm re-looking at this code (again), I realized that really what this code is doing is creating 2 random numbers, one which is labeled 'guess'. The while loop produces these 2 random numbers until they match, at which point the code ends.
am I missing anything?