11function pad ( num ) {
2+ // console.log(num)
23 let numString = num . toString ( ) ;
4+ // console.log(numString, "numstr")
35 while ( numString . length < 2 ) {
46 numString = "0" + numString ;
57 }
8+ // console.log(numString, "FULLNUM")
69 return numString ;
710}
811
12+
913function formatTimeDisplay ( seconds ) {
1014 const remainingSeconds = seconds % 60 ;
1115 const totalMinutes = ( seconds - remainingSeconds ) / 60 ;
@@ -14,25 +18,38 @@ function formatTimeDisplay(seconds) {
1418
1519 return `${ pad ( totalHours ) } :${ pad ( remainingMinutes ) } :${ pad ( remainingSeconds ) } ` ;
1620}
21+ console . log ( formatTimeDisplay ( 61 ) )
22+
23+
24+
1725
1826// You will need to play computer with this example - use the Python Visualiser https://pythontutor.com/visualize.html#mode=edit
1927// to help you answer these questions
2028
2129// Questions
2230
2331// a) When formatTimeDisplay is called how many times will pad be called?
24- // =============> write your answer here
32+ // =============> write your answer here
33+ // Answer below:
34+ // Pad runs once for "totalHours", once "remainingMinutes" and once for "remainingSeconds" in total pad is called 3 times.
2535
2636// Call formatTimeDisplay with an input of 61, now answer the following:
2737
2838// b) What is the value assigned to num when pad is called for the first time?
29- // =============> write your answer here
39+ // =============> write your answer here
40+ // Answer below:
41+ // The first pad is pad(totalHours) and the value is 0
3042
3143// c) What is the return value of pad when it is called for the first time?
3244// =============> write your answer here
45+ // The value is 0 plus the "0" added to it to make the value 00
3346
3447// 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
48+ // =============> write your answer here
49+ // Answer below:
50+ // The last call is pad(remainingSeconds) and the value is 1
3651
3752// 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
53+ // =============> write your answer here
54+ // Answer below:
55+ // the return value initially is 1 and "0" was added to it in front to make the value 01
0 commit comments