Skip to content

Commit 6ab0464

Browse files
committed
interpret time-format.js
1 parent c3d0e3a commit 6ab0464

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,29 @@ 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
2021

2122
// Questions
2223

2324
// a) When formatTimeDisplay is called how many times will pad be called?
24-
// =============> write your answer here
25+
// =============> pad will be called 3 times, once for each of the hours, minutes, and seconds values that are being formatted into a string.
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+
// =============>Pad is called for the first time with the value of 0, which is the total hours calculated from the input of 61 seconds.
31+
// The total hours is calculated by dividing the total minutes (1) by 60, which results in 0 hours. pad(totalHours)
3032

31-
// c) What is the return value of pad when it is called for the first time?
32-
// =============> write your answer here
33+
// c) What is the return value of pad is called for the first time?
34+
// =============> 0 is the value assigned to num when pad is called for the first time, and the return value of pad is "00". This is because the while loop in the pad function adds a leading zero to the string representation of num until its length is at least 2. Since num is 0, it becomes "00" after one iteration of the loop.
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+
// =============> pad(remainingSeconds) remainingSeconds =1, so num is +1. This is because the input to formatTimeDisplay is 61 seconds, which results in 1 second remaining after calculating the total minutes and hours. The pad function is called with this value to format it as a two-digit string for display.
3638

3739
// 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
40+
// =============> numString = "1" so string has only one character "01" the return value of pad when it is called for the last time in this program is "01".
41+
// This is because the while loop in the pad function adds a leading zero to the string representation of num until its length is at least 2.
42+
// Since num is 1, it becomes "01" after one iteration of the loop.

0 commit comments

Comments
 (0)