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
console.log(formatTimeDisplay(num));// should return "00:01:01"
15
+
16
+
13
17
14
18
// You will need to play computer with this example - use the Python Visualiser https://pythontutor.com/visualize.html#mode=edit
15
19
// to help you answer these questions
@@ -18,17 +22,18 @@ function formatTimeDisplay(seconds) {
18
22
19
23
// a) When formatTimeDisplay is called how many times will pad be called?
20
24
// =============> write your answer here
21
-
25
+
// The function pad will be called three times when formatTimeDisplay is called, once for each of; hours, minutes, and seconds.These are then passed as an argument to the pad function to ensure that they are displayed with two digits in the final output string.
22
26
// Call formatTimeDisplay with an input of 61, now answer the following:
23
27
24
28
// b) What is the value assigned to num when pad is called for the first time?
25
29
// =============> write your answer here
26
-
30
+
// The value assigned to num when pad is called for the first time is the totalHours value, which is 0. The value of 61 seconds is only one minute and one second, any value that includes hours must be in excess of 3600 seconds.
27
31
// c) What is the return value of pad is called for the first time?
28
32
// =============> write your answer here
29
-
33
+
// The return value of pad when it is called for the first time is "00". This is because the totalHours value is 0, and when it is converted to a string and passed to the pad function, it will be padded with a leading zero to ensure that it has two digits, resulting in "00".
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
32
-
36
+
// The value assigned to num when pad is called for the last time in this program is the remainingSeconds value, which is 1. This is because the input of 61 seconds results in 1 second remaining after accounting for the full minute.
33
37
// e) What is the return value assigned to num when pad is called for the last time in this program? Explain your answer
34
38
// =============> write your answer here
39
+
//This value displayed with two digits in the final output string, resulting in "01".
0 commit comments