Skip to content

Instantly share code, notes, and snippets.

@ryanbartley
Created May 31, 2014 17:00
Show Gist options
  • Save ryanbartley/bbdd3d643bf5a1411c04 to your computer and use it in GitHub Desktop.
Save ryanbartley/bbdd3d643bf5a1411c04 to your computer and use it in GitHub Desktop.
# Computer needs to generate a secret number
secret_number = rand(5) + 1
# initialize a variable called trys that equals 0
# begin the loop
# Tell the user to guess a number between 1 and 10
puts "guess a number between 1 and 5"
# User guesses a number
user_guess = gets.to_i
# If the guess was higher than the secret number print "Too high!"
if user_guess > secret_number
puts "Too High!"
# If the guess was lower than the secret number print "Too low!"
elsif user_guess < secret_number
puts "Too Low!"
# If the guess was equal to the secret number print "Congratulations!"
elsif user_guess == secret_number
puts "Good Job!"
puts "This is the number that ruby created #{secret_number}"
end
# increment the variable trys
# end the loop if user_guess is equal to secret_number
# put to the screen how many trys it took
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment