Skip to content

Commit 0e13a1a

Browse files
committed
Answering questions for time-format.js
1 parent d0032b7 commit 0e13a1a

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

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

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

1515
return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`;
1616
}
17+
console.log(formatTimeDisplay(61));
1718

1819
// You will need to play computer with this example - use the Python Visualiser https://pythontutor.com/visualize.html#mode=edit
1920
// to help you answer these questions
@@ -22,17 +23,30 @@ function formatTimeDisplay(seconds) {
2223

2324
// a) When formatTimeDisplay is called how many times will pad be called?
2425
// =============> write your answer here
26+
//pad will be called 3 times.
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?
2931
// =============> write your answer here
32+
// The value assigned to num when pad is called for the first time is 0.
3033

3134
// c) What is the return value of pad is called for the first time?
3235
// =============> write your answer here
36+
// The return value of pad when it is called for the first time is "00".
3337

3438
// d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer
3539
// =============> write your answer here
40+
// The value assigned to num when pad is called for the last time in this program is 1.
41+
// This is because the last call uses remainingSeconds, and for 61 seconds, remainingSeconds is 1.
3642

3743
// e) What is the return value of pad when it is called for the last time in this program? Explain your answer
3844
// =============> write your answer here
45+
// The return value of pad when it is called for the last time in this program is "01".
46+
//This is because the last call is pad(1), and the pad function adds a zero in front to make it two digits.
47+
/*function pad(1) {
48+
let numString = 1.toString(); // numString is "1"
49+
while (numString.length < 2) { // numString.length is 1, so the loop runs
50+
numString = "0" + numString; // numString becomes "01"
51+
return numString; // returns "01"
52+
}*/

0 commit comments

Comments
 (0)