A number guessing game with a lesson hidden inside
This number guessing game is the classic “higher or lower” challenge. The page picks a secret whole number in the range you choose — 1 to 10 for young children, 1 to 100 for the standard game, 1 to 1,000 or any custom range for a tougher round — and tells you after every guess whether the answer is higher or lower. It counts your attempts, remembers your best for each range, and can show you the binary-search tip that finds any number in 1–100 within seven guesses.
Flip the switch to Computer guesses and the roles reverse: you think of a number, the computer asks “Is it 50?”, and you answer higher, lower or correct. Watching it narrow the range by halves is the clearest demonstration of binary search you will find, and it catches you out if your answers contradict each other.
Nothing is sent anywhere; the secret number lives in your browser tab and your best scores stay on your device.
How to use the Number Guessing Game
- Choose a Range. Custom ranges accept any whole numbers, including negatives, and are swapped automatically if you enter them the wrong way round.
- Type a guess and press Guess or Enter. The panel says Higher! or Lower! and your attempts go up by one.
- Tick Show the binary-search tip if you want the game to show which numbers are still possible and the ideal next guess — the middle of that interval.
- When you hit the number, the panel says Correct, compares your attempts with the perfect count and saves your best for that range. Press New number to play again.
- In Computer guesses mode, think of a number in the range, then answer each question with My number is higher, My number is lower or Correct!.
Number Guessing Game features
Five ranges including custom
1–10, 1–50, 1–100, 1–1,000 or any range you type, with the “perfect player” attempt count calculated for each.
Clear clues and a guess log
Every guess is logged with an arrow, inputs outside the range or not whole numbers are refused with a message, and the panel colours change for higher, lower and correct.
Binary-search tip
An optional helper shows the remaining interval and the midpoint to guess next — switch it on to learn the technique, off to test yourself.
Computer guesses your number
The computer always guesses the midpoint of what is still possible, so it needs at most ⌈log₂(n)⌉ tries: 7 for 1–100, 10 for 1–1,000.
Contradiction detection
If your higher/lower answers rule out every number, the computer says so instead of looping forever — a gentle way to show why consistent clues matter.
Best scores per range
Your fewest attempts for each range are kept in your browser and can be cleared at any time.
Why seven guesses are always enough for 1–100
Guessing the middle of the remaining range halves the number of possibilities every time, whatever the clue. Start at 50: whichever answer you get, at most 50 numbers remain. Then 25 remain, then 12, 6, 3, 1 — and the seventh guess is certain. In general a range of n numbers needs at most ⌈log₂ n⌉ guesses, which grows very slowly:
- This is binary search, the same idea used to look up a word in a dictionary, find a bug by bisecting commits, or locate an item in a sorted list in computer science.
| Range | Numbers | Guesses needed (perfect play) |
|---|---|---|
| 1–10 | 10 | 4 |
| 1–50 | 50 | 6 |
| 1–100 | 100 | 7 |
| 1–1,000 | 1,000 | 10 |
| 1–1,000,000 | 1,000,000 | 20 |
Playing with children
Start with 1–10 and let a child guess freely; the Higher/Lower clues teach number order without any pressure. Move to 1–50 and switch on the tip for a few rounds, then off again, and ask them to explain why “guess the middle” works. Reversing the roles with Computer guesses is often the moment it clicks: children enjoy trying to beat the computer and quickly notice that it cannot be beaten by picking a “tricky” number. The random number generator is handy if two people want to play against each other away from the screen, and the hangman game gives the same higher-or-lower feeling with letters.
What counts as a good score?
On 1–100, seven attempts or fewer means you played perfectly or got a little lucky; eight to ten is a solid game; more than that usually means guesses were not landing in the middle of the remaining interval. Because the secret number is random, a perfect player will still sometimes need all seven — a score of one or two attempts is luck, not skill. The attempts counter only counts valid guesses inside the range, so a typo does not cost you.
Number Guessing Game FAQ
How do you play the number guessing game?
Pick a range, type a number and press Guess. The game tells you whether the secret number is higher or lower. Keep narrowing it down until you get “Correct”, then compare your attempts with the perfect count.
What is the best strategy for guess the number?
Always guess the middle of the numbers that are still possible. That halves the range every time and finds any number from 1 to 100 within seven guesses. Tick “Show the binary-search tip” to see the midpoint suggested.
Can the computer always guess my number?
Yes, as long as your higher/lower answers are truthful. It needs at most 7 guesses for 1–100 and 10 for 1–1,000. If the answers contradict each other it stops and tells you.
Can I use negative numbers or a huge range?
Yes. Choose Custom and type any two whole numbers. If the second is smaller than the first they are swapped, and the perfect-play attempt count updates for the new range.
Does the game remember my scores?
Your fewest attempts for each range are stored in your browser’s local storage on this device. Press Clear best scores to remove them.
Is the secret number really random?
Yes — it is picked in your browser when a round starts and is never shown until you guess it. Each New number press picks a fresh one.