Last active
August 29, 2015 14:06
-
-
Save hpjaj/f4ee70cf92a8c08637df to your computer and use it in GitHub Desktop.
week 3 - 6e def granny part 1
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
def start_program | |
puts "Soooo, what's new, sonny boy?" | |
gets_grandsons_input | |
end | |
def gets_grandsons_input | |
print "> " | |
@grandson_choice = gets.chomp | |
determines_if_grandma_heard | |
end | |
def determines_if_grandma_heard | |
if @grandson_choice == 'BYE' | |
exit_program | |
elsif @grandson_choice == @grandson_choice.upcase | |
calculates_grandmas_random_year_response | |
else | |
grandma_cannot_hear_you | |
end | |
end | |
def exit_program | |
puts "Goodbye sonny. Come back soon." | |
exit(0) | |
end | |
def calculates_grandmas_random_year_response | |
years_she_remembers = (1930..1950).to_a | |
random_number = rand(years_she_remembers.size) | |
@random_year = years_she_remembers[random_number] | |
grandma_responds_with_year(@random_year) | |
end | |
def grandma_responds_with_year(year) | |
puts "NO, NOT SINCE #{year}!" | |
gets_grandsons_input | |
end | |
def grandma_cannot_hear_you | |
puts "HUH?! SPEAK UP, SONNY!" | |
gets_grandsons_input | |
end | |
start_program |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment