Skip to content

Commit e1f2934

Browse files
committed
questions in regarding to pad() answered
1 parent d6cbfbd commit e1f2934

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,32 @@ 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?
2426
// =============> write your answer here
27+
//> pad() was called 3 times---> pad(totalHours)---> pad(remainingMinutes)---> pad(remainingSeconds)
2528

2629
// Call formatTimeDisplay with an input of 61, now answer the following:
30+
// formatTimeDisplay(61);
2731

2832
// b) What is the value assigned to num when pad is called for the first time?
2933
// =============> write your answer here
34+
// pad(totalHours)--> totalHours= 0 --> Therefore num = 0
3035

3136
// c) What is the return value of pad when it is called for the first time?
3237
// =============> write your answer here
38+
//the first pad() call returns the answer 00, this is because the value is 0, and functions adds a 0 to the beginning of the character to make it two characters long.
3339

3440
// d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer
3541
// =============> write your answer here
42+
// 3 pad calls---> 1)-> pad(0), 2)-> pad(1), 3)-> pad(1)---> this shows the last call pad(remainingSeconds) = remainingSeconds= 1. when we call formatTimeDisplay(61); indicates that there are 61 seconds, after taking away 60 seconds which makes it 1 minute and the remainder is 1 second.
3643

3744
// e) What is the return value of pad when it is called for the last time in this program? Explain your answer
3845
// =============> write your answer here
46+
// when calling formatTimeDisplay(61); we already figured out the last pad() call is pad (remainingSeconds) and know that remainingSeconds is 1. Inside pad the number changes into a string "1" and the function then calculates and checks the length of the string but we wanted 2 characters/digits at least. Hence why the function adds 0 to the beginning which then gives us "01".

0 commit comments

Comments
 (0)