Step-by-step solution for Time Convert
View the challenge

This challenge requires you to convert an integer, which represents the number of minutes, for example 63 means 214 minutes, and convert this integer into hours and minutes. So if the input was 63, then your program should output the string '1:3' because 63 minutes converts to 1 hour and 3 minutes. We will use the modulo operation to solve this challenge. The modulo operation simply returns the remainder after a division, so for example, the remainder of 5 / 2 is 1, so the modulo of 5 / 2 is 1.

function TimeConvert(num) { 

  // to get the hours, we divide num by 60 and round it down
  // e.g. 61 / 60 = 1 hour
  // e.g. 43 / 60 = 0 hours
  var hours = Math.floor(num / 60);

  // to get the minutes, now we use the remainder that we discarded above
  // the modulo operation is represented by the % symbol
  // e.g. 61 % 60 = 1 minute
  // e.g. 43 % 60 = 43 minutes
  var minutes = num % 60;

  // combine the hours and minutes
  return hours + ':' + minutes;
         
}
   
TimeConvert(124);                            
import math

def TimeConvert(num): 

  # to get the hours, we divide num by 60 and round it down
  # e.g. 61 / 60 = 1 hour
  # e.g. 43 / 60 = 0 hours
  hours = int(math.floor(num / 60))

  # to get the minutes, now we use the remainder that we discarded above
  # the modulo operation is represented by the % symbol
  # e.g. 61 % 60 = 1 minute
  # e.g. 43 % 60 = 43 minutes
  minutes = num % 60

  # combine the hours and minutes
  return str(hours) + ':' + str(minutes);
    
print TimeConvert(124)  
def TimeConvert(num)

  # to get the hours, we divide num by 60 and round it down
  # e.g. 61 / 60 = 1 hour
  # e.g. 43 / 60 = 0 hours
  hours = num / 60

  # to get the minutes, now we use the remainder that we discarded above
  # the modulo operation is represented by the % symbol
  # e.g. 61 % 60 = 1 minute
  # e.g. 43 % 60 = 43 minutes
  minutes = num % 60

  # combine the hours and minutes
  return hours.to_s + ':' + minutes.to_s
         
end
      
puts TimeConvert(STDIN.gets)  
Top User Solutions
1 hyuil Challenge Score: 10 Cpp
1 Qlogin Challenge Score: 10 Python
2 Sabin Challenge Score: 10 Python
1 junjunparkpark Challenge Score: 10 Ruby
1 cjordanball Challenge Score: 10 JavaScript
3 Corinto Challenge Score: 10 Python
4 mmalkavian Challenge Score: 10 Python
5 gzamfire Challenge Score: 10 Python
2 EmperorDuny Challenge Score: 10 JavaScript
2 lokeshmogra Challenge Score: 10 Cpp
3 cdms0 Challenge Score: 10 Cpp
3 jackgeek Challenge Score: 10 JavaScript
6 scates Challenge Score: 10 Python
7 ricky0309 Challenge Score: 10 Python
4 chrigolex Challenge Score: 10 JavaScript
8 philtroin Challenge Score: 10 Python
4 sanguookchoi Challenge Score: 10 Cpp
5 beeboop19 Challenge Score: 10 JavaScript
6 mattlarsh Challenge Score: 10 JavaScript
7 deuzen Challenge Score: 10 JavaScript
8 SuprDewd Challenge Score: 10 JavaScript
5 gutty333 Challenge Score: 10 Cpp
1 arjnklc Challenge Score: 10 Java
9 safetyscissors Challenge Score: 10 JavaScript
10 franko Challenge Score: 10 JavaScript
9 theBestFella Challenge Score: 10 Python
2 toasterbob Challenge Score: 10 Ruby
10 Abualleaf Challenge Score: 10 Python
3 gladysum Challenge Score: 10 Ruby
4 duncanbb Challenge Score: 10 Ruby
5 Bohdan Challenge Score: 10 Ruby
6 emuchynski Challenge Score: 10 Ruby
7 mienaineko Challenge Score: 10 Ruby
8 randyjap Challenge Score: 10 Ruby
1 ionutforyou Challenge Score: 10 PHP
9 kelaiyarao1 Challenge Score: 10 Ruby
6 Justification Challenge Score: 10 Cpp
10 CoderAPS Challenge Score: 10 Ruby
2 tostercx Challenge Score: 10 PHP
7 Zeikar Challenge Score: 10 Cpp
2 danaksim Challenge Score: 10 Java
3 jakmaj Challenge Score: 10 Java
4 mikejagen Challenge Score: 10 Java
5 binfeng Challenge Score: 10 Java
8 anta0 Challenge Score: 10 Cpp
6 ph4ntom Challenge Score: 10 Java
9 lingqyzeng Challenge Score: 10 Cpp
10 amatakos Challenge Score: 10 Cpp
7 k8conant Challenge Score: 10 Java
8 nicklivens Challenge Score: 10 Java
9 KSmithson Challenge Score: 10 Java
10 kester824 Challenge Score: 10 Java
3 longcheng Challenge Score: 10 PHP
4 torbjornperttu Challenge Score: 10 PHP
5 albionselimaj Challenge Score: 10 PHP
6 teplicko Challenge Score: 10 PHP
7 Althalus Challenge Score: 10 PHP
8 smcdowell Challenge Score: 10 PHP
9 jetonr Challenge Score: 10 PHP
10 mihainem Challenge Score: 10 PHP