Games

Number Guessing Game

Quick answer

In the number guessing game the computer picks a secret number and you try to guess it. After each guess you are told whether the secret number is higher or lower. The best strategy is to guess the middle of the remaining range, which finds any number from 1 to 100 in at most 7 guesses.

Found this useful? WhatsApp X LinkedIn

How it works

Choose a range, type a guess and press Guess. The game tells you whether to go higher or lower and shows the range that is still possible. Win in as few tries as you can. Your fewest tries for each range is saved on your device.

Maximum tries with the best strategy = ⌈log₂(range + 1)⌉

Examples

ExampleRange 1 to 100Start at 50. If it is higher, try 75, then 62 or 87, halving the range each time. You will find it in 7 tries or fewer.
ExampleRange 1 to 1000Halving each time finds any number in at most 10 tries.

About Number Guessing Game

The number guessing game is a classic first programming exercise and a simple way to learn binary search. The computer picks a secret number, and each hint of higher or lower removes half of the remaining possibilities if you guess the middle. This version has three ranges and tracks your fewest tries.

Why play the number guessing game

  • A quick game with children to practise number sense.
  • Learning how binary search works.
  • Settling small decisions with a game.
  • Beating your own best number of tries.

Tips to guess faster

  • Always guess the middle of the remaining range.
  • Use the range shown after each hint.
  • For 1 to 100, start at 50.
  • Try the 1 to 1000 range once you can win in 7 tries.

Common mistakes

  • Guessing numbers outside the range that is still possible.
  • Repeating a guess you already made.
  • Guessing near the edges instead of the middle.

Frequently asked questions

What is the best strategy?

Always guess the middle of the remaining range. This is called binary search, and it halves the possibilities each time.

How many guesses does 1 to 100 need?

At most 7 with the best strategy.

Is the number really random?

Yes. A new random number is chosen each round using your browser's random generator.

Is my score saved?

Your best score is stored in your own browser only. Nothing is uploaded.

Written by Jasveer Raj, software engineer · Last updated 3 Nov 2026

Esc