File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed
Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments