Skip to content

Commit 849f01e

Browse files
answered questions
1 parent f2897ab commit 849f01e

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

Sprint-2/4-mandatory-interpret/time-format.js

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,42 @@ function formatTimeDisplay(seconds) {
1010

1111
return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`;
1212
}
13+
console.log(formatTimeDisplay(61));
1314

1415
// You will need to play computer with this example - use the Python Visualiser https://pythontutor.com/visualize.html#mode=edit
1516
// to help you answer these questions
1617

1718
// Questions
1819

1920
// a) When formatTimeDisplay is called how many times will pad be called?
20-
// =============> write your answer here
21+
// =============> pad will be called 3 times, once for pad(totalHours,
22+
// once for (pad)remainingMinutes and once for (pad)remainingSeconds
23+
2124

2225
// Call formatTimeDisplay with an input of 61, now answer the following:
2326

2427
// b) What is the value assigned to num when pad is called for the first time?
25-
// =============> write your answer here
28+
// =============> The first call to pad is pad(totalHours).
29+
//totalHours is calculated as totalMinutes // 60.
30+
//For the input 61, seconds is 61, remainingSeconds is 1, and totalMinutes is 1.
31+
//So, totalHours is 1 // 60 = 0.
32+
//Therefore, num is assigned the value 0 when pad is called for the first time.
33+
2634

2735
// c) What is the return value of pad is called for the first time?
28-
// =============> write your answer here
36+
// =============> The first call to pad is pad(totalHours).
37+
//totalHours is calculated as totalMinutes // 60.
38+
//For the input 61, totalMinutes is (61 - 1) // 60 = 1.
39+
//So, totalHours is 1 // 60 = 0.
40+
//pad(0) returns the string representation of 0, padded with zeros to a minimum length of 2, which is "00".
41+
2942

3043
// d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer
31-
// =============> write your answer here
44+
// =============> We look at the last call to pad, which is pad(remaining_seconds).
45+
//remaining_seconds is calculated as seconds % 60.
46+
//For the input 61, seconds % 60 equals 1.
47+
//So, pad(remaining_seconds) is equivalent to pad(1). The value assigned to num in the last call to pad is 1.
48+
3249

3350
// e) What is the return value assigned to num when pad is called for the last time in this program? Explain your answer
34-
// =============> write your answer here
51+
// =============> For the input 61, remaining_seconds will be 1. So, pad(1) will return "01". Therefore, the value assigned to num is 1.

0 commit comments

Comments
 (0)