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

JavaScript JavaScript Basics (Retired) Making Decisions with Conditional Statements Improving the Random Number Guessing Game

Andrew Chung
Andrew Chung
5,203 Points

How does the program know the number should be more or less?

This might be an incredibly stupid question but I don't see how the program knows the next number should be more or less. If the user doesn't guess correctly, then the program will alert them that the number should be more or less than their guess. However, how does the program know to make the next number more or less if it's random?

2 Answers

Hey Andrew,

The way I understand it is that the program only returns one random number because Math.random is only ever used once, so it isn't asking the player to guess another number that Math.random will generate.

It is only the player's guess that ever changes, not the random number.

The players second guess will either match the same, unchanged, random number that Math.random first returned, or it won't match it.

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

If we're talking about random numbers then the program is looking for a number between 0 and 1. I don't know anything about how it works of what makes it but it uses calculations on the Base 10 numbering system and takes up computer memory and CPU speeds.

I basically think what happens is when JS is making number comparisons its looking for a certain pattern of 0s and 1s. :)