Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # suplement exercises
- # return "HELLO <your name>!" in this method
- # return "HELLO WORLD!" if name is empty
- # this method is shouting so you just need
- # need to upcase the result
- def shout(name)
- name = 'WORLD' if name.empty?
- "HELLO #{name.upcase}!"
- end
- # return "Drink served!" if the birth date was more
- # than 18 years ago.
- # return "Go Home!" if is below 18 years or "Drink Served"
- # otherwise
- def can_drink(birth_date)
- age = (Date.today - birth_date).to_i / 365
- if age >= 18
- 'Drink Served!'
- else
- 'Go Home!'
- end
- end
- # return the average number between min and max in the Float format
- # # be carefull! sometimes they will be a string that needs
- # to be converted
- def average(min, max)
- sum = 0
- (min..max).each do |i|
- sum += i
- end
- sum.to_f / (max - min + 1)
- end
- # return the multiplication table of a number given
- # in the parameters up until he reaches max_multiplier
- # # it should return a string with the following format
- # (example for number 3 and max_multiplier 10)
- # 1x3=3
- # 2x3=6
- # 3x3=9
- # 3x4=12
- # ...
- # 3x10=30
- # this method should return a string with each
- # computation in each line. you can use \n to do a new line
- def multiplication_table(number, max_multiplier)
- table = []
- (1..max_multiplier).each do |i|
- table << "#{number}x#{i}=#{number * i}"
- end
- table.join("\n")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement