Skip to content

Instantly share code, notes, and snippets.

@barbchoy
Last active September 29, 2017 05:25
Show Gist options
  • Save barbchoy/87ac0a1f7920702e9e6a9ca4e01d6952 to your computer and use it in GitHub Desktop.
Save barbchoy/87ac0a1f7920702e9e6a9ca4e01d6952 to your computer and use it in GitHub Desktop.
null created by barbchoy - https://repl.it/Br7M/3332
# 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