Skip to content

Instantly share code, notes, and snippets.

Created September 20, 2019 17:38
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
A number guessing game in ruby, built during the Girl Code Amsterdam Meetup on the 18. September 2019
def play_game(start_range, end_range)
computer_guess = rand(start_range..end_range)
user_guesses = []
puts "Guess a number"
user_guess = gets.chomp.to_i
while user_guess != computer_guess
if user_guesses.include?(user_guess)
puts "You've already tried this number, try again"
puts "Wrong! Guess again"
user_guesses << user_guess # Add user guess to the array of previous guesses
user_guess = gets.chomp.to_i
puts "Congrats, you guessed it"
def run()
puts "Welcome to the number guessing game!"
puts "Do you want to play a game? [y/n]"
start_game = gets.chomp.downcase # Ignore the case by always using lower case
while(start_game == "y") # Allow the user to keep playing if they finish a game
puts "What range do you want to guess between?"
start_range = gets.chomp.to_i
puts "and"
end_range = gets.chomp.to_i
play_game(start_range, end_range)
puts "Do you want to play another game? [y/n]"
start_game = gets.chomp
puts "Boo, stopping game"
run() # Start the game
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment