Skip to content

Commit e4092fa

Browse files
committed
Create Time Convert
1 parent 90d4aa7 commit e4092fa

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

Time Convert

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/***************************************************************************************
2+
* *
3+
* CODERBYTE BEGINNER CHALLENGE *
4+
* *
5+
* Time Convert *
6+
* Using the JavaScript language, have the function TimeConvert(num) take the num *
7+
* parameter being passed and return the number of hours and minutes the parameter *
8+
* converts to (ie. if num = 63 then the output should be 1:3). Separate the number *
9+
* of hours and minutes with a colon. *
10+
* *
11+
* SOLUTION *
12+
* There are 60 minutes in an hour. To find the number of hours divide the num by *
13+
* 60 and use the Math.floor to convert to whole hours. Next use the modulus *
14+
* function to get the minutes.
15+
* *
16+
* Steps for solution *
17+
* 1) Get hours by dividing num by 60 to get whole number of hours *
18+
* 2) Get minutes by using modulus function *
19+
* 3) Combine hours and minutes in required format and return as answer *
20+
* *
21+
***************************************************************************************/
22+
23+
function TimeConvert(num) {
24+
25+
var hours = Math.floor(num / 60);
26+
var minutes = num % 60;
27+
return hours + ":" + minutes;
28+
29+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy