Skip to content

Commit ce9cf2e

Browse files
Implement time formatting and padding functions
1 parent 81f329a commit ce9cf2e

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,36 @@ function pad(num) {
55
}
66
return numString;
77
}
8+
console.log(pad());
89

910
function formatTimeDisplay(seconds) {
1011
const remainingSeconds = seconds % 60;
1112
const totalMinutes = (seconds - remainingSeconds) / 60;
1213
const remainingMinutes = totalMinutes % 60;
1314
const totalHours = (totalMinutes - remainingMinutes) / 60;
14-
1515
return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`;
1616
}
17+
console.log(formatTimeDisplay(61));
1718

19+
//
1820
// You will need to play computer with this example - use the Python Visualiser https://pythontutor.com/visualize.html#mode=edit
1921
// to help you answer these questions
2022

2123
// Questions
2224

2325
// a) When formatTimeDisplay is called how many times will pad be called?
24-
// =============> write your answer here
26+
// =============> three times in terms of hours, minutes and seconds
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
31+
// =============> 0
3032

3133
// c) What is the return value of pad is called for the first time?
32-
// =============> write your answer here
34+
// =============> 00
3335

3436
// 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
37+
// =============> the value assigned to num will be 1, and because the remaining seconds after 61 % 60 will be 1.
3638

3739
// 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
40+
// =============> the return value of pad when it is called for the last time is "01". Because inside pad(), 1 is less than 2, and will be padded to "0" and will become "01".

0 commit comments

Comments
 (0)