Skip to content

Commit c1fab78

Browse files
Add time format functionality
1 parent 63cc7a9 commit c1fab78

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ function pad(num) {
33
while (numString.length < 2) {
44
numString = "0" + numString;
55
}
6+
console.log(numString);
67
return numString;
78
}
89

@@ -15,24 +16,26 @@ function formatTimeDisplay(seconds) {
1516
return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`;
1617
}
1718

19+
console.log(formatTimeDisplay(61));
20+
1821
// You will need to play computer with this example - use the Python Visualiser https://pythontutor.com/visualize.html#mode=edit
1922
// to help you answer these questions
2023

2124
// Questions
2225

2326
// a) When formatTimeDisplay is called how many times will pad be called?
24-
// =============> write your answer here
27+
// =============> write your answer here: ***Answer*** :Function pad will be called 3 times.
2528

2629
// Call formatTimeDisplay with an input of 61, now answer the following:
2730

28-
// b) What is the value assigned to num when pad is called for the first time?
29-
// =============> write your answer here
31+
// b) What is the value assigned to num when pad is called for the first time?:
32+
// =============> write your answer here: ***Answer*** : The value assigned to num =61.
3033

3134
// c) What is the return value of pad when it is called for the first time?
32-
// =============> write your answer here
35+
// =============> write your answer here: ***Answer*** :The value of pad when it is called for the first time is "00".
3336

34-
// 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+
// d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer:
38+
// =============> write your answer here: ***Answer***: The last call of pad in this program is pad(remainingSeconds) => remainingSeconds= (61%60=1) => num = 1.
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+
// =============> write your answer here : ***Answer*** : The value of pad when is called for the last time is the third part in `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}` => pad(remainingSeconds)=pad(1) since 1 has a length <2 return will be padded with 0 => pad (1)return "01".

0 commit comments

Comments
 (0)