Last active
December 23, 2015 23:19
-
-
Save ahimmelstoss/6708897 to your computer and use it in GitHub Desktop.
ruby lecture 1 quiz
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 seconds_in_minutes(minutes) | |
minutes * 60 | |
end | |
puts seconds_in_minutes(2) | |
def minutes_in_hours(hours) | |
hours * 60 | |
end | |
puts minutes_in_hours(3) | |
def hours_in_days(days) | |
days * 24 | |
end | |
puts hours_in_days(3) | |
def days_in_weeks(weeks) | |
weeks * 7 | |
end | |
puts days_in_weeks(3) | |
def weeks_in_years(years) | |
years * 52 | |
end | |
puts weeks_in_years(2) | |
def years_in_decades(decades) | |
decades * 10 | |
end | |
puts years_in_decades(2) | |
# Hours in a year. How many hours are in a year? | |
def hours_in_years(years) | |
years * hours_in_days(days_in_weeks(weeks_in_years(1))) | |
end | |
puts hours_in_years(1) | |
# Minutes in a decade. How many minutes are in a decade? | |
def minutes_in_decade(decade) | |
decade * minutes_in_hours(hours_in_days(days_in_weeks(weeks_in_years(years_in_decades(1))))) | |
end | |
puts minutes_in_decade(1) | |
# Your age in seconds. How many seconds old are you? | |
def age_in_seconds(age) | |
age * seconds_in_minutes(minutes_in_hours(hours_in_days(days_in_weeks(weeks_in_years(1))))) | |
end | |
puts age_in_seconds(24) | |
# If I am 1,111 million seconds old, how old am I? | |
# Define an age_from_seconds method | |
def age_from_seconds(seconds) | |
seconds / seconds_in_minutes(minutes_in_hours(hours_in_days(days_in_weeks(weeks_in_years(1))))) | |
end | |
puts age_from_seconds(1111000000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment