Powered by AppSignal & Oban Pro
Would you like to see your link here? Contact us

Games: Guessing Game

exercises/games_guessing_game.livemd

Games: Guessing Game

Mix.install([
  {:jason, "~> 1.4"},
  {:kino, "~> 0.9", override: true},
  {:youtube, github: "brooklinjazz/youtube"},
  {:hidden_cell, github: "brooklinjazz/hidden_cell"}
])

Navigation

Home Report An Issue Games ProjectGames: Rock Paper Scissors

Games: Guessing Game

In your existing Games project, you’re going to create a number guessing game which accepts user input through the command line.

You should be able to start your project by running the following from the game folder in the command line.

iex -S mix

Then you can start the game with the Games.GuessingGame module.

Games.GuessingGame should prompt the user to guess a number between 1 and 10.

iex> Games.GuessingGame.play()
Guess a number between 1 and 10:

If the guess is correct, return a winning message.

Guess a number between 1 and 10: 10
You win!

if the guess is incorrect, return a failing message.

Guess a number between 1 and 10: 1
Incorrect!

Bonus: Re-Attempt

If the guess is incorrect, re-prompt the user to enter another guess until they succeed. This is harder problem than you might expect! See the future lesson on Recursion for more information.

Enter your guess: 10
Incorrect!
Enter your guess: 5
Incorrect!
Enter your guess: 7
Correct!

Bonus: High Or Low!

If the guess is too high or low, prompt the user with informative feedback.

Enter your guess: 10
Too High!
Enter your guess: 5
Too Low!
Enter your guess: 7
Correct!

Limited Attempts

Give the user 5 attempts to guess the answer. Print a losing message and end the game if they don’t guess the answer.

Enter your guess: 10
Too high!
Enter your guess: 9
Too high!
Enter your guess: 8
Too high!
Enter your guess: 7
Too high!
Enter your guess: 6
Too high!
Enter your guess: 5
You lose! the answer was 4
iex> 

Commit Your Progress

DockYard Academy now recommends you use the latest Release rather than forking or cloning our repository.

Run git status to ensure there are no undesirable changes. Then run the following in your command line from the curriculum folder to commit your progress.

$ git add .
$ git commit -m "finish Games: Guessing Game exercise"
$ git push

We’re proud to offer our open-source curriculum free of charge for anyone to learn from at their own pace.

We also offer a paid course where you can learn from an instructor alongside a cohort of your peers. We will accept applications for the June-August 2023 cohort soon.

Navigation

Home Report An Issue Games ProjectGames: Rock Paper Scissors