Created
September 3, 2017 17:31
-
-
Save jochri3/5c10190fe9a4b37ddad167eeabef27af to your computer and use it in GitHub Desktop.
null created by ChrisLis - https://repl.it/HaJg/106
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 function that will take in a number of minutes, and returns a | |
// string that formats the number into `hours:minutes`. | |
// | |
// Difficulty: easy. | |
function time_conversion(minutes) | |
{ | |
if(minutes<60)return "0:"+minutes | |
else if(minutes==60)return "1:00" | |
else | |
{ | |
var rest=0 | |
var heure=0 | |
var rest=0 | |
while(minutes>=60) | |
{ | |
if(minutes>=60) | |
{ | |
minutes -=60 | |
rest=minutes | |
heure +=1 | |
} | |
if(minutes==0) | |
{ | |
minutes="00" | |
} | |
} | |
return heure+":"+minutes | |
} | |
} | |
console.log(time_conversion(120)) | |
// These are tests to check that your code is working. After writing | |
// your solution, they should all print true. | |
console.log("\nTests for //time_conversion") | |
console.log("===============================================") | |
console.log('time_conversion(15) == "0:15": ' + (time_conversion(15) == '0:15')) | |
console.log('time_conversion(150) == "2:30": ' + (time_conversion(150) == '2:30')) | |
console.log('time_conversion(360) == "6:00": ' + (time_conversion(360) == '6:00')) | |
console.log("===============================================") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment