Last active
September 29, 2017 05:25
-
-
Save barbchoy/87ac0a1f7920702e9e6a9ca4e01d6952 to your computer and use it in GitHub Desktop.
null created by barbchoy - https://repl.it/Br7M/3332
This file contains hidden or 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
# Write a method that will take in a number of minutes, and returns a | |
# string that formats the number into `hours:minutes`. | |
# | |
# Difficulty: easy. | |
def time_conversion(minutes) | |
hour=0 | |
mins=0 | |
string_hr_mins="" | |
hour=minutes/60 | |
mins=minutes%60 | |
if mins===0 | |
mins="00" | |
string_hr_mins="#{hour}:00" | |
else | |
string_hr_mins="#{hour}:#{mins}" | |
end | |
return string_hr_mins | |
end | |
# These are tests to check that your code is working. After writing | |
# your solution, they should all print true. | |
puts("\nTests for #time_conversion") | |
puts("===============================================") | |
puts('time_conversion(15) == "0:15": ' + (time_conversion(15) == '0:15').to_s) | |
puts('time_conversion(150) == "2:30": ' + (time_conversion(150) == '2:30').to_s) | |
puts('time_conversion(360) == "6:00": ' + (time_conversion(360) == '6:00').to_s) | |
puts("===============================================") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment