You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// You will need to play computer with this example - use the Python Visualiser https://pythontutor.com/visualize.html#mode=edit
15
16
// to help you answer these questions
@@ -18,17 +19,23 @@ function formatTimeDisplay(seconds) {
18
19
19
20
// a) When formatTimeDisplay is called how many times will pad be called?
20
21
// =============> write your answer here
22
+
//Answer: it is called 3 times once for each of the three calls to pad in the formatTimeDisplay function in line 11 return statement.
21
23
22
24
// Call formatTimeDisplay with an input of 61, now answer the following:
23
25
24
26
// b) What is the value assigned to num when pad is called for the first time?
25
27
// =============> write your answer here
28
+
// Answer: The first call to pad is for totalHours which is 0. because 61 seconds is less than 3600 seconds (1 hour) the totalHours will be 0.
26
29
27
30
// c) What is the return value of pad is called for the first time?
28
31
// =============> write your answer here
32
+
// Answer: The first call to pad will return "00" because it converts the number 0 to a string and pads it with leading zeros to ensure it is at least 2 characters long.
29
33
30
34
// d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer
31
35
// =============> write your answer here
36
+
// Answer: The last call to pad is for remainingSeconds which is 1. The value assigned to num will be 1 because it is the remaining seconds after calculating total hours and total minutes.
32
37
33
38
// e) What is the return value assigned to num when pad is called for the last time in this program? Explain your answer
34
39
// =============> write your answer here
40
+
// Answer: The last call to pad will return "01" because it converts the number 1 to a string and pads it with leading zeros to ensure it is at least 2 characters long.
0 commit comments