Skip to content

Commit c0e52cb

Browse files
committed
done time-format.js
1 parent 120c3f7 commit c0e52cb

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

Sprint-2/interpret/time-format.js

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
function pad(num) {
2+
console.log(num);
23
return num.toString().padStart(2, "0");
34
}
45

@@ -7,25 +8,32 @@ function formatTimeDisplay(seconds) {
78
const totalMinutes = (seconds - remainingSeconds) / 60;
89
const remainingMinutes = totalMinutes % 60;
910
const totalHours = (totalMinutes - remainingMinutes) / 60;
10-
11-
return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(
12-
remainingSeconds
13-
)}`;
11+
return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`;
1412
}
1513

16-
// You will need to play computer with this example - use the Python Visualiser https://pythontutor.com/visualize.html#mode=edit
17-
// to help you answer these questions
14+
console.log(formatTimeDisplay(61));
15+
16+
/*
17+
You will need to play computer with this example - use the Python Visualiser https://pythontutor.com/visualize.html#mode=edit
18+
to help you answer these questions
1819
19-
// Questions
20+
Questions
2021
21-
// a) When formatTimeDisplay is called how many times will pad be called?
22+
a) When formatTimeDisplay is called how many times will pad be called?
23+
- 3 times, pad is called three times, once for each part of the time: hours, minutes, and seconds.
2224
23-
// Call formatTimeDisplay with an input of 61, now answer the following:
25+
Call formatTimeDisplay with an input of 61, now answer the following:
26+
2427
25-
// b) What is the value assigned to num when pad is called for the first time?
28+
b) What is the value assigned to num when pad is called for the first time?
29+
- 0, because the first pad is totalHours and we don't have any hours yet, only minutes
2630
27-
// c) What is the return value of pad is called for the first time?
31+
c) What is the return value of pad is called for the first time?
32+
- "00" and calling formatTimeDisplay(61) = 00:01:01
2833
29-
// d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer
34+
d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer
35+
- In this case, the value of num before it is passed to pad is 1 (the remainder when 61 are divided by 60).
3036
31-
// e) What is the return value assigned to num when pad is called for the last time in this program? Explain your answer
37+
e) What is the return value assigned to num when pad is called for the last time in this program? Explain your answer
38+
- After pad processes 1, it will return the value "01" because it ensures the number is two digits long (by adding a leading zero)
39+
*/

0 commit comments

Comments
 (0)