Guessing Game
Guessing Game

Guessing Game

Learning Exercise

While completing Guessing Game, you'll learn 1 concept


In this exercise, you are playing a number guessing game with a friend. The rules are simple: you secretly choose a number between 1 and 100 and your friend tries to guess what number you've chosen. To help your friend, you respond differently depending on how close the guess was to the number you've chosen (42). These are the rules for the different possible inputs:

  • If the guess is 42: "Correct"
  • If the guess is 41 or 43: "So close"
  • If the guess is less than 41: "Too low"
  • If the guess is greater than 43: "Too high"

You have four tasks to encode the replies to the guesses.

1. Reply to a correct guess

Implement the reply function to reply to a correct guess:

reply 42
-- -> "Correct"

2. Reply to a close guess

Modify the reply function to reply to close guesses:

reply 41
-- -> "So close"

3. Reply to too low guesses

Modify the reply function to reply to too low guesses:

reply 25
-- -> "Too low"

4. Reply to too high guesses

Modify the reply function to reply to too high guesses:

reply 88
-- -> "Too high"
Last updated 1 February 2023
Edit via GitHub The link opens in a new window or tab
Haskell Exercism

Ready to start Guessing Game?

Sign up to Exercism to learn and master Haskell with 100 exercises, and real human mentoring, all for free.