Skip to content

Commit 2c69c5e

Browse files
Complete Sprint-3 interpret exercise (time-format.js)
1 parent d1aba8e commit 2c69c5e

1 file changed

Lines changed: 26 additions & 13 deletions

File tree

‎Sprint-3/4-mandatory-interpret/time-format.js‎

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,41 @@ function formatTimeDisplay(seconds) {
1111
const totalMinutes = (seconds - remainingSeconds) / 60;
1212
const remainingMinutes = totalMinutes % 60;
1313
const totalHours = (totalMinutes - remainingMinutes) / 60;
14-
1514
return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`;
1615
}
1716

18-
// You will need to play computer with this example - use the Python Visualiser https://pythontutor.com/visualize.html#mode=edit
17+
// You will need to play computer with this example – use the Python Visualiser https://pythontutor.com/visualize.html#mode=edit
1918
// to help you answer these questions
2019

2120
// Questions
2221

2322
// a) When formatTimeDisplay is called how many times will pad be called?
24-
// =============> write your answer here
23+
// ==============> write your answer here
24+
// pad will be called 3 times — once for totalHours, once for remainingMinutes,
25+
// and once for remainingSeconds, since all three appear inside the template
26+
// literal on the return line.
2527

2628
// Call formatTimeDisplay with an input of 61, now answer the following:
2729

2830
// b) What is the value assigned to num when pad is called for the first time?
29-
// =============> write your answer here
30-
31-
// c) What is the return value of pad when it is called for the first time?
32-
// =============> write your answer here
33-
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
36-
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
31+
// ==============> write your answer here
32+
// num = 0 (this is totalHours, since (61-1)/60 = 1 minute total, and
33+
// (1-1)/60 = 0 hours, and pad(totalHours) is the first call in the template
34+
// literal)
35+
36+
// c) What is the return value of pad it is called for the first time?
37+
// ==============> write your answer here
38+
// "00" — pad(0) converts 0 to the string "0", which has length 1, so a
39+
// leading "0" is added, making it "00"
40+
41+
// d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer
42+
// ==============> write your answer here
43+
// num = 1 (this is remainingSeconds — 61 % 60 = 1 — and pad(remainingSeconds)
44+
// is the last of the three pad() calls in the template literal)
45+
46+
// e) What is the return value of pad when it is called for the last time in this program? Explain your answer
47+
// ==============> write your answer here
48+
// "01" — pad(1) converts 1 to the string "1", which has length 1, so a
49+
// leading "0" is added, making it "01"
50+
51+
console.log(formatTimeDisplay(61)); // "00:01:01"

0 commit comments

Comments
 (0)