Skip to content

Commit ba8e540

Browse files
author
Ogbemi mene
committed
my explanation to the code
1 parent 5208285 commit ba8e540

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,25 @@ function formatTimeDisplay(seconds) {
2121
// Questions
2222

2323
// a) When formatTimeDisplay is called how many times will pad be called?
24-
// =============> write your answer here
24+
// pad will be called 3 times. Inside the return statement of formatTimeDisplay,
25+
// pad is called once for totalHours, once for remainingMinutes, and once for remainingSeconds.
2526

2627
// Call formatTimeDisplay with an input of 61, now answer the following:
2728

2829
// b) What is the value assigned to num when pad is called for the first time?
29-
// =============> write your answer here
30+
// Answer: 0. Reason: The first evaluation in the template literal is pad(totalHours).
31+
// Since totalHours is 0, 0 is passed as the argument to num.
3032

3133
// c) What is the return value of pad is called for the first time?
32-
// =============> write your answer here
34+
// answer: "00". Reason: The while loop in pad checks if the length of numString is less than 2.
35+
// Since numString is "0", the loop runs and adds a "0" to the front, making it "00".
36+
// The loop then checks again, and since the length is now 2, it exits and returns "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
35-
// =============> write your answer here
39+
// Answer: 1. Reason: The last evaluation in the template literal is pad(remainingSeconds).
40+
// Since remainingSeconds is 1, 1 is passed as the argument to num.
3641

3742
// 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
43+
// Answer: "01". Reason: The while loop in pad checks if the length of numString is less than 2.
44+
// Since numString is "1", the loop runs and adds a "0" to the front, making it "01".
45+
// The loop then checks again, and since the length is now 2, it exits and returns "01".

0 commit comments

Comments
 (0)