Skip to content

Commit f9f9cdd

Browse files
Sprint 2 Task 4 Exercise time-format completed
1 parent 5dc9a63 commit f9f9cdd

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,30 @@ 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 pad function is called upon 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?
29-
// =============> write your answer here
31+
// num is = 0
3032

3133
// c) What is the return value of pad is called for the first time?
32-
// =============> write your answer here
34+
// the return value is "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+
// the value assigned is 1 this is because when the value 61 is passed into the formatTimeDisplay function it sends totalHours,
38+
// remainingMinutes and remainingSeconds in that order to the pad function. Since we know the remainingSeconds is sent last
39+
// and that 61 divided by 60 leaves us with a remainder of 1 we know 1 will be the last value assigned to num.
3640

3741
// 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
42+
// the return value will be "01" as when the value 1 is passed into the pad function it is converted into a string, which is "1" in this case,
43+
// that string is then passed into a while loop which checks if the string is less than two characters and adds a "0" to the start of the string
44+
// so "1" becomes "01" and is then returned.

0 commit comments

Comments
 (0)