Search⌘ K
AI Features

Solution 9: Guess the Number

Explore how to build a number guessing game in Ruby by implementing loops, user input handling, and conditional checks to control game flow and outcomes.

Flowchart of a possible solution

We are tasked to create a game in which the program will select a random number from a given collection and the user will try to guess that number. The user would have unlimited attempts to guess the number. The program will only terminate if the user successfully guesses the correct number or enters “stop” to end the game. Below is the flowchart of one possible solution:

The flowchart above tells us that we need to code the following ...