Skip to content

Commit 8c166ff

Browse files
fix: add console log and comments for clarity in formatTimeDisplay function
1 parent bb731c1 commit 8c166ff

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ function formatTimeDisplay(seconds) {
1010

1111
return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`;
1212
}
13+
console.log(formatTimeDisplay(61)); // Expected output: "00:01:01"
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
@@ -18,17 +19,23 @@ function formatTimeDisplay(seconds) {
1819

1920
// a) When formatTimeDisplay is called how many times will pad be called?
2021
// =============> write your answer here
22+
//Answer: it is called 3 times once for each of the three calls to pad in the formatTimeDisplay function in line 11 return statement.
2123

2224
// 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?
2527
// =============> write your answer here
28+
// Answer: The first call to pad is for totalHours which is 0. because 61 seconds is less than 3600 seconds (1 hour) the totalHours will be 0.
2629

2730
// c) What is the return value of pad is called for the first time?
2831
// =============> write your answer here
32+
// Answer: The first call to pad will return "00" because it converts the number 0 to a string and pads it with leading zeros to ensure it is at least 2 characters long.
2933

3034
// d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer
3135
// =============> write your answer here
36+
// Answer: The last call to pad is for remainingSeconds which is 1. The value assigned to num will be 1 because it is the remaining seconds after calculating total hours and total minutes.
3237

3338
// e) What is the return value assigned to num when pad is called for the last time in this program? Explain your answer
3439
// =============> write your answer here
40+
// Answer: The last call to pad will return "01" because it converts the number 1 to a string and pads it with leading zeros to ensure it is at least 2 characters long.
41+

0 commit comments

Comments
 (0)