-
Notifications
You must be signed in to change notification settings - Fork 91
/
Copy pathTime Convert
29 lines (26 loc) · 1.91 KB
/
Time Convert
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/***************************************************************************************
* *
* CODERBYTE BEGINNER CHALLENGE *
* *
* Time Convert *
* Using the JavaScript language, 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. *
* *
* SOLUTION *
* There are 60 minutes in an hour. To find the number of hours divide the num by *
* 60 and use the Math.floor to convert to whole hours. Next use the modulus *
* function to get the minutes.
* *
* Steps for solution *
* 1) Get hours by dividing num by 60 to get whole number of hours *
* 2) Get minutes by using modulus function *
* 3) Combine hours and minutes in required format and return as answer *
* *
***************************************************************************************/
function TimeConvert(num) {
var hours = Math.floor(num / 60);
var minutes = num % 60;
return hours + ":" + minutes;
}