Skip to content

Commit 90cb423

Browse files
committed
time-format.js committed
1 parent c1b8638 commit 90cb423

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

Sprint-2/4-mandatory-interpret/time-format.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,54 @@ function formatTimeDisplay(seconds) {
1919
// a) When formatTimeDisplay is called how many times will pad be called?
2020
// =============> write your answer here
2121

22+
/**
23+
* formatTimeDisplay calls pad three times inside the template literal: once for hours, once for minutes, once for seconds.
24+
*/
25+
2226
// Call formatTimeDisplay with an input of 61, now answer the following:
2327

2428
// b) What is the value assigned to num when pad is called for the first time?
2529
// =============> write your answer here
2630

31+
/**
32+
* Value of num when pad is called first time:
33+
* pad(totalHours) -> num = 0
34+
*/
35+
2736
// c) What is the return value of pad is called for the first time?
2837
// =============> write your answer here
2938

39+
/**
40+
* Return value of pad first time:
41+
* "0".padStart(2, "0") = "00"
42+
*/
43+
3044
// d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer
3145
// =============> write your answer here
3246

47+
/**
48+
* Value of num when pad is called last time:
49+
* Last pad call is pad(remainingSeconds) -> remainingSeconds = 1, so num = 1
50+
*/
51+
3352
// e) What is the return value assigned to num when pad is called for the last time in this program? Explain your answer
3453
// =============> write your answer here
54+
55+
/**
56+
* Return value of last pad call:
57+
* "1".padStart(2, "0") = "01"
58+
*/
59+
60+
/**
61+
* To recap all responses:
62+
*
63+
* (a) 3
64+
* (b) 0
65+
* (c) "00"
66+
* (d) 1 — because remainingSeconds is calculated first and holds 1, then after pad(totalHours) and pad(remainingMinutes) have finished, the final call is with that remainingSeconds variable, which is still 1.
67+
* (e) "01" — because 1 is padded with a leading zero making a two-character string "01".
68+
*/
69+
70+
// Calling the function formatTimeDisplay passing the 12,000 seconds as argument
71+
console.log(formatTimeDisplay(12000)) //return 03:20:00
72+

0 commit comments

Comments
 (0)