@@ -15,24 +15,20 @@ function formatTimeDisplay(seconds) {
1515 return `${ pad ( totalHours ) } :${ pad ( remainingMinutes ) } :${ pad ( remainingSeconds ) } ` ;
1616}
1717
18- // You will need to play computer with this example - use the Python Visualiser https://pythontutor.com/visualize.html#mode=edit
19- // to help you answer these questions
18+ // a) pad is called 3 times per call to formatTimeDisplay (once for hours, minutes, seconds).
2019
21- // Questions
20+ // Call formatTimeDisplay(61):
21+ // remainingSeconds = 61 % 60 = 1
22+ // totalMinutes = (61 - 1) / 60 = 1
23+ // remainingMinutes = 1 % 60 = 1
24+ // totalHours = (1 - 1) / 60 = 0
25+ // pad is called with: totalHours=0, remainingMinutes=1, remainingSeconds=1
2226
23- // a) When formatTimeDisplay is called how many times will pad be called?
24- // =============> write your answer here
27+ // b) num = 0 (totalHours) when pad is called for the first time.
2528
26- // Call formatTimeDisplay with an input of 61, now answer the following:
29+ // c) pad(0): "0".length < 2, so prepend "0" -> "00". Return value: "00"
2730
28- // b) What is the value assigned to num when pad is called for the first time?
29- // =============> write your answer here
31+ // d) num = 1 (remainingSeconds) when pad is called for the last time.
32+ // It is the last argument passed in the template literal.
3033
31- // c) What is the return value of pad is called for the first time?
32- // =============> write your answer here
33-
34- // 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
36-
37- // 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
34+ // e) pad(1): "1".length < 2, so prepend "0" -> "01". Return value: "01"
0 commit comments