Skip to content

Instantly share code, notes, and snippets.

@ebinmore
Last active June 27, 2016 15:03
Show Gist options
  • Save ebinmore/86b2f7b08f2f00e6e177d86b4d3e8df8 to your computer and use it in GitHub Desktop.
Save ebinmore/86b2f7b08f2f00e6e177d86b4d3e8df8 to your computer and use it in GitHub Desktop.
Game we wrote during Kids Learning Code
puts "Let's play a game of number guessing from 1 to 100!"
hidden_value = rand(1..100)
max_guesses = 10
winner = false
attempt = 1
while attempt <= max_guesses && !winner do
puts "Guess #{attempt}/#{max_guesses}: What do you think the number is?"
my_guess = gets.chomp.to_i
if my_guess == hidden_value
puts "YOU ARE CORRECT! You got it in attempt #{attempt}"
winner = true
else
puts "Sorry, that was not the number... try again"
attempt = attempt.next
if my_guess > hidden_value
puts "You're guess is too high!"
else
puts "You're guess is too low!"
end
end
end
puts "Sorry, the number was #{hidden_value}" unless winner
gets
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment