Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Luke-Rogerson/f5b2f40489cde59c169430192c5cc9cc to your computer and use it in GitHub Desktop.
Save Luke-Rogerson/f5b2f40489cde59c169430192c5cc9cc to your computer and use it in GitHub Desktop.
TimeConvert algorithm challenge created by Luke_Rogerson - https://repl.it/@Luke_Rogerson/TimeConvert-algorithm-challenge
/*
Have the function TimeConvert(num) take the num parameter being passed and return the number of hours and minutes the parameter converts to (ie. if num = 63 then the output should be 1:3). Separate the number of hours and minutes with a colon.
Input:126
Output:"2:6"
Input:45
Output:"0:45"
*/
// If (input / 60) < 1
// return (0 + ":" + input)
// Else if (input / 60) > 1)
// return ((input/60.slice[0])+(input%60)
function TimeConvert (num) {
if ((num / 60) < 1 ) {
return (0 + ":" + num);
}
else if ((num / 60) > 1) {
return (Math.floor(num / 60)) + ":" + (num % 60);
}
}
TimeConvert(512);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment