You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Sprint-2/4-mandatory-interpret/time-format.js
+38Lines changed: 38 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -19,16 +19,54 @@ function formatTimeDisplay(seconds) {
19
19
// a) When formatTimeDisplay is called how many times will pad be called?
20
20
// =============> write your answer here
21
21
22
+
/**
23
+
* formatTimeDisplay calls pad three times inside the template literal: once for hours, once for minutes, once for seconds.
24
+
*/
25
+
22
26
// Call formatTimeDisplay with an input of 61, now answer the following:
23
27
24
28
// b) What is the value assigned to num when pad is called for the first time?
25
29
// =============> write your answer here
26
30
31
+
/**
32
+
* Value of num when pad is called first time:
33
+
* pad(totalHours) -> num = 0
34
+
*/
35
+
27
36
// c) What is the return value of pad is called for the first time?
28
37
// =============> write your answer here
29
38
39
+
/**
40
+
* Return value of pad first time:
41
+
* "0".padStart(2, "0") = "00"
42
+
*/
43
+
30
44
// d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer
31
45
// =============> write your answer here
32
46
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
+
33
52
// e) What is the return value assigned to num when pad is called for the last time in this program? Explain your answer
34
53
// =============> 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
0 commit comments