Created
August 20, 2013 01:53
-
-
Save ashleytbasinger/9ff5ee0948c44d722282 to your computer and use it in GitHub Desktop.
guess the number game for ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
number = rand(0...100) | |
puts "Let's play a game!" | |
print "Guess a number between 0 and 100:" | |
loop do | |
guess = gets.chomp | |
if !/^\d+$/.match(guess) | |
puts 'Invalid guess, try again...' | |
print "guess again: " | |
elsif guess.to_i > number | |
puts "too high" | |
print "guess again: " | |
elsif guess.to_i < number | |
puts "too low" | |
print "guess again: " | |
else guess.to_i == number | |
puts "correct" | |
break | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment