Skip to content

Commit e5ebd4a

Browse files
committed
Answer time format interpretation questions
1 parent 072cfc4 commit e5ebd4a

1 file changed

Lines changed: 7 additions & 29 deletions

File tree

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,16 @@
1-
function pad(num) {
2-
let numString = num.toString();
3-
while (numString.length < 2) {
4-
numString = "0" + numString;
5-
}
6-
return numString;
7-
}
8-
9-
function formatTimeDisplay(seconds) {
10-
const remainingSeconds = seconds % 60;
11-
const totalMinutes = (seconds - remainingSeconds) / 60;
12-
const remainingMinutes = totalMinutes % 60;
13-
const totalHours = (totalMinutes - remainingMinutes) / 60;
14-
15-
return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`;
16-
}
17-
18-
// You will need to play computer with this example - use the Python Visualiser https://pythontutor.com/visualize.html#mode=edit
19-
// to help you answer these questions
20-
21-
// Questions
22-
231
// a) When formatTimeDisplay is called how many times will pad be called?
24-
// =============> write your answer here
2+
// =============> 3
253

264
// Call formatTimeDisplay with an input of 61, now answer the following:
275

286
// b) What is the value assigned to num when pad is called for the first time?
29-
// =============> write your answer here
7+
// =============> 0
308

319
// c) What is the return value of pad when it is called for the first time?
32-
// =============> write your answer here
10+
// =============> "00"
3311

34-
// 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
12+
// d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer
13+
// =============> 1, because the remaining seconds are 1.
3614

37-
// 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
15+
// e) What is the return value of pad when it is called for the last time in this program? Explain your answer
16+
// =============> "01", because pad adds a 0 to the front of 1.

0 commit comments

Comments
 (0)