Skip to content

Instantly share code, notes, and snippets.

@kat-perreira
Created March 3, 2018 23:05
Show Gist options
  • Save kat-perreira/097540fbf95f4a523928eea5f00e9fd5 to your computer and use it in GitHub Desktop.
Save kat-perreira/097540fbf95f4a523928eea5f00e9fd5 to your computer and use it in GitHub Desktop.
Patronus spell created by kaimana_Cat - https://repl.it/@kaimana_Cat/Patronus-spell
=begin
Write a Deaf Grandma program. Whatever you say to grandma (whatever you type in), she should respond with HUH?! SPEAK UP, SONNY!, unless you shout it (type in all capitals). If you shout, she can hear you (or at least she thinks so) and yells back, NO, NOT SINCE 1938! To make your program really believable, have grandma shout a different year each time; maybe any year at random between 1930 and 1950. (This part is optional, and would be much easier if you read the section on Ruby's random number generator at the end of the methods chapter.) You can't stop talking to grandma until you shout BYE.
Hint: Don't forget about chomp! 'BYE'with an Enter is not the same as 'BYE' without one!
Hint 2: Try to think about what parts of your program should happen over and over again. All of those should be in your while loop.
=end
# Ask user to say a spell. accept as user_input
puts "Please enter your name"
name = gets.chomp
print "Hello "
print name
puts ", lets see if you can summon a patronous. With all your might, please recite the spell...NOW!"
user_input = gets.chomp
# while spell is lowercase, put more power needed try a little louder
while user_input.start_with?(user_input.downcase)
puts "spark...spark...fizzle. Not quite, try a little louder!"
user_input = gets.chomp
end
#if loud put random patronous
if user_input.start_with?(user_input.upcase)
print "*spark* *Spark* *SPARK*.......BOOOOOOM!!!!!"
puts
print "A "
print [:Bear, :Bunny, :Dog, :Otter, :Horse, :Cat, :TerrorBird, :Lion].sample
print " appears! Excelent job! "
end
#Unlock secret reward
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment