@@ -15,24 +15,35 @@ function formatTimeDisplay(seconds) {
1515 return `${ pad ( totalHours ) } :${ pad ( remainingMinutes ) } :${ pad ( remainingSeconds ) } ` ;
1616}
1717
18+ console . log ( formatTimeDisplay ( 61 ) )
19+
1820// You will need to play computer with this example - use the Python Visualiser https://pythontutor.com/visualize.html#mode=edit
1921// to help you answer these questions
2022
2123// Questions
2224
2325// a) When formatTimeDisplay is called how many times will pad be called?
24- // =============> write your answer here
26+ // =============> 3 times pad() will be called
2527
2628// Call formatTimeDisplay with an input of 61, now answer the following:
2729
2830// b) What is the value assigned to num when pad is called for the first time?
29- // =============> write your answer here
31+ // =============> 0 is the value assigned to num.
3032
3133// c) What is the return value of pad when it is called for the first time?
32- // =============> write your answer here
34+ // =============> 00 is the value of pad when it was called for the first time.
3335
3436// 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
37+ // =============> 1 is the value of num when the pad is called for the last time. The last time pad is called is
38+ // by by putting "remaining seconds" which is 1 in the function pad .
3639
3740// 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
41+ // =============> 01 is the return value of pad.when pad()is called with the value of num 1 the expression
42+ // inside the pad function evaluates to a value 01. If we go through the code
43+ // function pad(num) {
44+ //let numString = num.toString();===> the value of numstring becomes "1"
45+ //while (numString.length < 2) { ===> this line it is checking if numString.length< 2, numString.length is 1 in this line
46+ //numString = "0" + numString; ===> in this line numString will be 01. and again will go to while again to check if
47+ // } numString.length is <2 and it is not then pad() will return 01.
48+ //
49+ //
0 commit comments