Created
September 17, 2014 03:25
-
-
Save deedeelavinder/bfb4271bdeed4c274715 to your computer and use it in GitHub Desktop.
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
repeat = nil | |
puts '' | |
puts'' | |
puts "Let's play a game. " .chomp | |
invitation = "I'll choose a number between 1 and 100 and you guess what it is. You'll have five trys." | |
puts invitation | |
puts "" | |
until repeat == "no" | |
answer = rand(1..100) | |
num_trys = 0 | |
userguess = nil | |
hit = "Hit me with your best shot:" | |
puts hit | |
while num_trys < 4 && userguess != answer | |
puts "" | |
userguess= gets.chomp.to_i | |
if userguess > answer | |
puts "Whoops, that's too high. Try again." | |
puts hit | |
puts "" | |
elsif userguess < answer | |
puts "Whoops, that's too low. Try again." | |
puts hit | |
puts "" | |
end | |
num_trys = num_trys + 1 | |
end | |
if num_trys == 4 && userguess != answer | |
puts "" | |
userguess= gets.chomp.to_i | |
num_trys = num_trys + 1 | |
end | |
if userguess == answer | |
puts "WOW, you guessed correctly. What are the odds? Maybe you should buy a lottery ticket. " | |
end | |
if num_trys == 5 && userguess != answer | |
puts "Bummer, you are out of guesses!" | |
puts "" | |
print "The correct answer was " + answer.to_s + "." | |
end | |
puts "" | |
puts "Thanks for playing." | |
puts "" | |
puts "Would you like to play again?" | |
puts "" | |
repeat= gets.chomp.to_s | |
if repeat == "yes" | |
puts "" | |
puts "Cool, me too!" | |
puts "Remember, " + invitation | |
puts "" | |
end | |
end | |
if repeat == "no" | |
puts "" | |
puts "Cool, neither do I. See you around." | |
puts "" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment