Search⌘ K
AI Features

Number Guessing Game

Explore how to create an interactive number guessing game in Ruby that involves generating random numbers, using if-elsif-else branching, and managing loops to handle user input until the correct guess is made.

Problem

Write a program that generates a secret a number (0–9) that the user guesses. The program prompts the user to enter a guess and gives feedback, such as "too big" or "too small." The program ends when the correct answer is entered.

I have a secret number (0 - 9), Can you guess it?
=> (you type 9)
Too big!
=> (you type 4)
Too Small!
=> (you type 5)
Correct! You guessed 3 times.
Number guessing game

Purpose

  • Branching with ...