@@ -15,20 +15,25 @@ function formatTimeDisplay(seconds) {
1515 return `${ pad ( totalHours ) } :${ pad ( remainingMinutes ) } :${ pad ( remainingSeconds ) } ` ;
1616}
1717
18- // a) pad is called 3 times per call to formatTimeDisplay (once for hours, minutes, seconds).
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
1920
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
21+ // Questions
2622
27- // b) num = 0 (totalHours) when pad is called for the first time.
23+ // a) When formatTimeDisplay is called how many times will pad be called?
24+ // =============> pad is called 3 times per call to formatTimeDisplay (once for totalHours, once for remainingMinutes, once for remainingSeconds).
2825
29- // c) pad(0): "0".length < 2, so prepend "0" -> "00". Return value: "00"
26+ // Call formatTimeDisplay with an input of 61, now answer the following:
27+ // (remainingSeconds = 1, totalMinutes = 1, remainingMinutes = 1, totalHours = 0)
3028
31- // d) num = 1 (remainingSeconds) when pad is called for the last time.
32- // It is the last argument passed in the template literal.
29+ // b) What is the value assigned to num when pad is called for the first time?
30+ // =============> num = 0 (totalHours), because totalHours is the first argument in the template literal.
3331
34- // e) pad(1): "1".length < 2, so prepend "0" -> "01". Return value: "01"
32+ // c) What is the return value of pad when it is called for the first time?
33+ // =============> "00" — "0".length < 2, so "0" is prepended, giving "00".
34+
35+ // d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer
36+ // =============> num = 1 (remainingSeconds). It is the last argument passed in the template literal, so pad is called with it last.
37+
38+ // e) What is the return value of pad when it is called for the last time in this program? Explain your answer
39+ // =============> "01" — "1".length < 2, so "0" is prepended, giving "01".
0 commit comments