Skip to content

Commit 8481cbe

Browse files
Answer debugging questions for formatTimeDisplay and pad function
1 parent a4076fc commit 8481cbe

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

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

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,36 @@ function formatTimeDisplay(seconds) {
88
const remainingMinutes = totalMinutes % 60;
99
const totalHours = (totalMinutes - remainingMinutes) / 60;
1010

11-
return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`;
11+
return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`;
1212
}
1313

14-
// You will need to play computer with this example - use the Python Visualiser https://pythontutor.com/visualize.html#mode=edit
14+
console.log(formatTimeDisplay(61))
15+
16+
// You will need to play computer with this example - use the Python Visualizer 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
21-
22-
// Call formatTimeDisplay with an input of 61, now answer the following:
23+
// ans: 3 times
24+
// Call formatTimeDisplay with an input of 61, now answer the following:
2325

2426
// b) What is the value assigned to num when pad is called for the first time?
25-
// =============> write your answer here
26-
27-
// c) What is the return value of pad is called for the first time?
28-
// =============> write your answer here
27+
// =============> write your answer here : 0
28+
// c) What is the return value of pad is called for the first time?
29+
// =============> write your answer here value : 00
2930

3031
// 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
32-
32+
// =============> write your answer here : 1 When formatTimeDisplay(61) is called, the value 61 is passed as the argument to seconds.
33+
// Then remainingSeconds is calculated using seconds % 60, which gives 1.
34+
// The last call to pad is pad(remainingSeconds).
35+
// Since remainingSeconds is 1, the value assigned to num in the last call is 1.
3336
// 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
37+
// =============> write your answer here : 01 When formatTimeDisplay(61) is called, the value 1 is passed to pad during the last call because remainingSeconds equals 1.
38+
// Inside the pad function:
39+
// The number 1 is converted to a string.
40+
// padStart(2, "0") ensures the string has at least two characters.
41+
// Since "1" has only one character, a "0" is added to the beginning.
42+
// So "1" becomes "01".
43+
// This ensures the time format follows the 00:00:00 structure.

0 commit comments

Comments
 (0)