Skip to content

Commit 481cdd2

Browse files
committed
added explanation about the function call
1 parent 6e72bf1 commit 481cdd2

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

‎Sprint-3/4-mandatory-interpret/time-format.js‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,29 @@ function formatTimeDisplay(seconds) {
1515
return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`;
1616
}
1717

18+
console.log(formatTimeDisplay(61));
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+
// The function pad will be called three 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?
29-
// =============> write your answer here
31+
// num is assigned value of totalHours when pad is called first time because js evaluates expressions from left to right
3032

3133
// c) What is the return value of pad when it is called for the first time?
32-
// =============> write your answer here
34+
// The return value will be "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+
// num will be assigned the value of remainingSeconds when pad is called for the last time because js evaluates any expression
38+
// from left to right and the pad with argument remainingSeconds is found at the right end
3639

3740
// 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
41+
// The return value of pad when it is called for the last time is "01"
42+
// We calculated remainingSeconds in the function formatTimeDisplay and we got the value 1 then when pad is called with
43+
// an argument value of remainingSeconds we changed the value to string and 0 is added before 1 and it became 2 digits which is "01"

0 commit comments

Comments
 (0)