Skip to content

Instantly share code, notes, and snippets.

@csoreff
Last active August 29, 2015 14:15
Show Gist options
  • Save csoreff/52b1fd16aa5f88b82a1c to your computer and use it in GitHub Desktop.
Save csoreff/52b1fd16aa5f88b82a1c to your computer and use it in GitHub Desktop.
Deaf Grandma
#Corey LeBlanc
def grandma()
puts "What would you like to say to Grandma?"
year = Random.new #Initialize new random object
byecount = 0 #Keeps track how how many BYEs in a row
while byecount != 3 #Keep chatting until you yell BYE three times
string = gets.chomp
if string != string.upcase #If string not all in upcase, then Grandma can't hear you
puts "HUH?! SPEAK UP, SONNY!"
end
if string == "BYE" #Did you yell BYE?
byecount+=1 #If so, add 1 to byecount
puts(byecount == 3 ? "OH, GOODBYE!" : "WHAT?") #She says "WHAT?" if you haven't said bye 3 times, else goodbye
end
unless string == "BYE" #If you say anything except BYE, byecount reverts back to 0
byecount = 0
end
#Interpolate the random object within range of 1930 and 1950
puts "NO, NOT SINCE #{year.rand(1930..1950)}!" if (string==string.upcase&&string!="BYE")
end
end
grandma
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment