11function pad ( num ) {
2- return num . toString ( ) . padStart ( 2 , "0" ) ;
2+ console . log ( num ) ;
3+ const result = num . toString ( ) . padStart ( 2 , "0" ) ;
4+ console . log ( result ) ;
5+ return result ;
36}
47
58function formatTimeDisplay ( seconds ) {
@@ -8,30 +11,35 @@ function formatTimeDisplay(seconds) {
811 const remainingMinutes = totalMinutes % 60 ;
912 const totalHours = ( totalMinutes - remainingMinutes ) / 60 ;
1013
11- return `${ pad ( totalHours ) } :${ pad ( remainingMinutes ) } :${ pad ( remainingSeconds ) } ` ;
14+ const time = `${ pad ( totalHours ) } :${ pad ( remainingMinutes ) } :${ pad ( remainingSeconds ) } ` ;
15+ console . log ( time ) ;
16+ return time ;
1217}
1318
19+ formatTimeDisplay ( 61 ) ;
20+
1421// You will need to play computer with this example - use the Python Visualiser https://pythontutor.com/visualize.html#mode=edit
1522// to help you answer these questions
1623
1724// Questions
1825
1926// a) When formatTimeDisplay is called how many times will pad be called?
2027// =============> write your answer here
21- // Pad is called once .
28+ // Pad is called three times in line 11 of the formatTimeDisplay() .
2229// Call formatTimeDisplay with an input of 61, now answer the following:
2330
2431// b) What is the value assigned to num when pad is called for the first time?
2532// =============> write your answer here
26- // value of num=undefined
33+ // value of num=0
2734// c) What is the return value of pad is called for the first time?
2835// =============> write your answer here
29- // it returns a function object
36+ // it returns 00
3037
3138// d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer
3239// =============> write your answer here
33- //value is 0
34- //the frame side when pad is called the last time num is assigned a value of 0
40+ //value is 1
41+ //the frame side when pad is called the last time num is assigned a value of 01
3542
3643// e) What is the return value assigned to num when pad is called for the last time in this program? Explain your answer
37- // =============> write your answer here
44+ // =============> write your answer here num is assigned a value of one when pad is called for the
45+ // last time by the formatTimeDisplay function this value is used to evaluate the remaining seconds.
0 commit comments