@@ -21,18 +21,41 @@ function formatTimeDisplay(seconds) {
2121// Questions
2222
2323// a) When formatTimeDisplay is called how many times will pad be called?
24- // =============> write your answer here
24+ // =============> write your answer here: three calls to pad() in the return statement:
25+ //return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`;
2526
2627// Call formatTimeDisplay with an input of 61, now answer the following:
2728
2829// b) What is the value assigned to num when pad is called for the first time?
29- // =============> write your answer here
30+ // =============> write your answer here:
31+ //For formatTimeDisplay(61):
32+ //remainingSeconds = 61 % 60 = 1
33+ //totalMinutes = (61 - 1) / 60 → 1
34+ //remainingMinutes = 1 % 60 → 1
35+ //totalHours = (1 - 1) / 60 → 0
36+ //num = 1
3037
3138// c) What is the return value of pad when it is called for the first time?
32- // =============> write your answer here
39+ // =============> write your answer here:num is 0.
40+ //let numString = num.toString(); gives us 0
41+
42+ // This loop adds a "0" because the string has only one character:
43+ //numString = "0" + "0";
44+ //return value is:
45+ //"00"
3346
3447// d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer
35- // =============> write your answer here
48+ // =============> write your answer here:
49+ //The last call is: pad(remainingSeconds)
50+
51+ //For 61 seconds, remainingSeconds is 61 % 60 = 1:
52+ //so num = 1
3653
3754// e) What is the return value of pad when it is called for the last time in this program? Explain your answer
38- // =============> write your answer here
55+ // =============> write your answer here:
56+ //num is 1, so:
57+ //num.toString() gives "1".
58+
59+ // and this loop adds a 0 to the beginning: "01"
60+
61+ //So the final result of formatTimeDisplay(61) is: 00:01:01
0 commit comments