Skip to content

Commit d34a28d

Browse files
committed
Display time in usual format
1 parent 886d971 commit d34a28d

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,44 @@ function formatTimeDisplay(seconds) {
1111
return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`;
1212
}
1313

14+
/**
15+
*
1416
// You will need to play computer with this example - use the Python Visualiser https://pythontutor.com/visualize.html#mode=edit
1517
// to help you answer these questions
1618
1719
// Questions
1820
1921
// a) When formatTimeDisplay is called how many times will pad be called?
2022
// =============> write your answer here
23+
Answer: 3 times (once for hours, once for minutes, once for seconds)
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?
2528
// =============> write your answer here
29+
First call: pad(totalHours) → num = 0
30+
Answer: 0
2631
2732
// c) What is the return value of pad is called for the first time?
2833
// =============> write your answer here
34+
"0".padStart(2, "0") → "00"
35+
Answer: "00"
2936
3037
// d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer
3138
// =============> write your answer here
39+
Last call: pad(remainingSeconds) → num = 1
40+
41+
Explanation: remainingSeconds = 61 % 60 = 1
42+
Answer: 1
3243
3344
// e) What is the return value assigned to num when pad is called for the last time in this program? Explain your answer
3445
// =============> write your answer here
46+
"1".padStart(2, "0") → "01"
47+
48+
Explanation: padStart(2, "0") ensures a 2-character string with a leading zero if needed.
49+
Answer: "01"
50+
*
51+
*/
52+
53+
console.log(formatTimeDisplay(61)); // "00:01:01"
54+

0 commit comments

Comments
 (0)