Skip to content

Commit 401db2b

Browse files
committed
In 4-mandatory-interpret/time-format.js, filled in answers
1 parent 6c1636f commit 401db2b

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1+
let timesToBeCalled = 0;
2+
13
function pad(num) {
4+
timesToBeCalled += 1;
5+
console.log(
6+
` Pad has been called ${timesToBeCalled} times and num is ${num}`
7+
);
8+
console.log(` The return value will be ${num.toString().padStart(2, "0")}`);
29
return num.toString().padStart(2, "0");
310
}
411

@@ -11,24 +18,36 @@ function formatTimeDisplay(seconds) {
1118
return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`;
1219
}
1320

21+
console.log(formatTimeDisplay(61));
22+
1423
// You will need to play computer with this example - use the Python Visualiser https://pythontutor.com/visualize.html#mode=edit
1524
// to help you answer these questions
1625

1726
// Questions
1827

1928
// a) When formatTimeDisplay is called how many times will pad be called?
2029
// =============> write your answer here
30+
// The pad function will be called 3 times when formatTimeDisplay is called.
31+
// 1st: for totalHours
32+
// 2nd: for remainingMinutes
33+
// 3rd: for remainingSeconds
2134

2235
// Call formatTimeDisplay with an input of 61, now answer the following:
2336

2437
// b) What is the value assigned to num when pad is called for the first time?
2538
// =============> write your answer here
39+
// The value assigned to num is 0 when pad is called for the first time because 61 seconds is 0 hours, 1 minute, and 1 second.
2640

2741
// c) What is the return value of pad is called for the first time?
2842
// =============> write your answer here
43+
// The return value of pad is "00" in string format because 0 is padded to 2 digits with leading zeros.
2944

3045
// d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer
3146
// =============> write your answer here
47+
// The value assigned to num is 1 when pad is called for the last time.
48+
// It is because the remaining seconds is 1 second after taken 60 seconds for 1 minute.
3249

3350
// e) What is the return value assigned to num when pad is called for the last time in this program? Explain your answer
3451
// =============> write your answer here
52+
// The return value assigned to num is "01" in string format.
53+
// It is because 1 second is padded to 2 digits with a leading zero.

0 commit comments

Comments
 (0)