#leah petersen #homework 2-16-16 "hours-in-a-year" #format number strings with US-style commas def separate_comma(number) whole, decimal = number.to_s.split(".") whole_with_commas = whole.chars.to_a.reverse.each_slice(3).map(&:join).join(",").reverse [whole_with_commas, decimal].compact.join(".") end #compute hours (24) in a year (365.25) hours_in_year = 24 * 365.25 puts "There are " + separate_comma(hours_in_year) + " hours in a year." #compute minutes (60 in hour) in a decade (10 years) mins_in_year = hours_in_year * 60 mins_in_decade = mins_in_year * 10 puts "There are " + separate_comma(mins_in_decade) + " minutes in a decade." #compute how many seconds old I am (31 years) secs_in_year = mins_in_year * 60 age_in_seconds = secs_in_year * 31 puts "I am " + separate_comma(age_in_seconds) + " seconds old." #compute Jeremy's age in years, he is 1,136,086,041.6 seconds old jeremys_age = 1136086041.6 / secs_in_year jeremys_age = jeremys_age.round puts "Jeremy is " + separate_comma(jeremys_age) + " years old."