11function pad ( num ) {
2+ console . log ( num ) ;
23 return num . toString ( ) . padStart ( 2 , "0" ) ;
34}
45
@@ -7,25 +8,32 @@ function formatTimeDisplay(seconds) {
78 const totalMinutes = ( seconds - remainingSeconds ) / 60 ;
89 const remainingMinutes = totalMinutes % 60 ;
910 const totalHours = ( totalMinutes - remainingMinutes ) / 60 ;
10-
11- return `${ pad ( totalHours ) } :${ pad ( remainingMinutes ) } :${ pad (
12- remainingSeconds
13- ) } `;
11+ return `${ pad ( totalHours ) } :${ pad ( remainingMinutes ) } :${ pad ( remainingSeconds ) } ` ;
1412}
1513
16- // You will need to play computer with this example - use the Python Visualiser https://pythontutor.com/visualize.html#mode=edit
17- // to help you answer these questions
14+ console . log ( formatTimeDisplay ( 61 ) ) ;
15+
16+ /*
17+ You will need to play computer with this example - use the Python Visualiser https://pythontutor.com/visualize.html#mode=edit
18+ to help you answer these questions
1819
19- // Questions
20+ Questions
2021
21- // a) When formatTimeDisplay is called how many times will pad be called?
22+ a) When formatTimeDisplay is called how many times will pad be called?
23+ - 3 times, pad is called three times, once for each part of the time: hours, minutes, and seconds.
2224
23- // Call formatTimeDisplay with an input of 61, now answer the following:
25+ Call formatTimeDisplay with an input of 61, now answer the following:
26+
2427
25- // b) What is the value assigned to num when pad is called for the first time?
28+ b) What is the value assigned to num when pad is called for the first time?
29+ - 0, because the first pad is totalHours and we don't have any hours yet, only minutes
2630
27- // c) What is the return value of pad is called for the first time?
31+ c) What is the return value of pad is called for the first time?
32+ - "00" and calling formatTimeDisplay(61) = 00:01:01
2833
29- // d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer
34+ d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer
35+ - In this case, the value of num before it is passed to pad is 1 (the remainder when 61 are divided by 60).
3036
31- // e) What is the return value assigned to num when pad is called for the last time in this program? Explain your answer
37+ e) What is the return value assigned to num when pad is called for the last time in this program? Explain your answer
38+ - After pad processes 1, it will return the value "01" because it ensures the number is two digits long (by adding a leading zero)
39+ */
0 commit comments