1- let timesToBeCalled = 0 ;
2-
31function pad ( num ) {
4- timesToBeCalled += 1 ;
5- console . log (
6- ` Pad has been called ${ timesToBeCalled } times and num is ${ num } `
7- ) ;
8- console . log ( ` The return value will be ${ num . toString ( ) . padStart ( 2 , "0" ) } ` ) ;
92 return num . toString ( ) . padStart ( 2 , "0" ) ;
103}
114
@@ -18,36 +11,24 @@ function formatTimeDisplay(seconds) {
1811 return `${ pad ( totalHours ) } :${ pad ( remainingMinutes ) } :${ pad ( remainingSeconds ) } ` ;
1912}
2013
21- console . log ( formatTimeDisplay ( 61 ) ) ;
22-
2314// You will need to play computer with this example - use the Python Visualiser https://pythontutor.com/visualize.html#mode=edit
2415// to help you answer these questions
2516
2617// Questions
2718
2819// a) When formatTimeDisplay is called how many times will pad be called?
2920// =============> write your answer here
30- // The pad function will be called 3 times when formatTimeDisplay is called.
31- // 1st: for totalHours
32- // 2nd: for remainingMinutes
33- // 3rd: for remainingSeconds
3421
3522// Call formatTimeDisplay with an input of 61, now answer the following:
3623
3724// b) What is the value assigned to num when pad is called for the first time?
3825// =============> write your answer here
39- // The value assigned to num is 0 when pad is called for the first time because 61 seconds is 0 hours, 1 minute, and 1 second.
4026
4127// c) What is the return value of pad is called for the first time?
4228// =============> write your answer here
43- // The return value of pad is "00" in string format because 0 is padded to 2 digits with leading zeros.
4429
4530// d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer
4631// =============> write your answer here
47- // The value assigned to num is 1 when pad is called for the last time.
48- // It is because the remaining seconds is 1 second after taken 60 seconds for 1 minute.
4932
5033// e) What is the return value assigned to num when pad is called for the last time in this program? Explain your answer
5134// =============> write your answer here
52- // The return value assigned to num is "01" in string format.
53- // It is because 1 second is padded to 2 digits with a leading zero.
0 commit comments