@@ -19,16 +19,73 @@ function formatTimeDisplay(seconds) {
1919// a) When formatTimeDisplay is called how many times will pad be called?
2020// =============> write your answer here
2121
22- // Call formatTimeDisplay with an input of 61, now answer the following:
22+ Answer: 3
23+
24+ return `${ pad ( totalHours ) } :${ pad ( remainingMinutes ) } :${ pad ( remainingSeconds ) } ` ;
25+
26+ pad is called three times: for totalHours , remainingMinutes , and remainingSeconds .
27+
28+ So no matter what input we give to formatTimeDisplay , pad will always be called 3 times .
2329
30+ // Call formatTimeDisplay with an input of 61, now answer the following:
2431// b) What is the value assigned to num when pad is called for the first time?
2532// =============> write your answer here
2633
34+ Answer ;
35+
36+ The first call is pad ( totalHours ) .
37+
38+ const totalHours = ( totalMinutes - remainingMinutes ) / 60 ;
39+
40+ The value assigned to num when pad is called for the first time is 0.
41+ Consequently , pad ( 0 ) will return '00' , which ensures that the hour is formatted correctly in the final output string
42+
43+
2744// c) What is the return value of pad is called for the first time?
2845// =============> write your answer here
2946
47+ Answer ; 1
48+
49+ return num . toString ( ) . padStart ( 2 , "0" ) ;
50+
51+ num = 1
52+
53+ num . toString ( ) = "1"
54+
55+ "1" . padStart ( 2 , "0" ) = "01"
56+
57+ If you call pad ( 0 ) , the return value will be '00' .
58+
59+ If you call pad ( 1 ) , the return value will be '01' .
60+
61+ If you call pad ( 5 ) , the return value will be '05' .
62+
63+ If you call pad ( 10 ) , the return value will be '10'
64+
65+
66+
3067// d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer
3168// =============> write your answer here
69+ Answer ; 1
70+
71+ The last call is pad ( remainingSeconds ) .
72+
73+ When you call format_time_display ( 61 ) :
74+
75+ The calculations result in :
76+
77+ total_hours = 0
78+ remaining_minutes = 1
79+ remaining_seconds = 1
80+
3281
3382// e) What is the return value assigned to num when pad is called for the last time in this program? Explain your answer
3483// =============> write your answer here
84+ Answwer ; 01
85+
86+
87+ Third Call : pad ( remaining_seconds ) ( where remaining_seconds = 1 )
88+
89+ Value of num for the last call : 1
90+
91+ Return value : '01'
0 commit comments