Skip to content

Commit 558ea37

Browse files
committed
docs: explanation how is iterating both functions when they are invoke, one is to separate hours, minutes and seconds and the pad() is formatting the time displayed
1 parent 298e008 commit 558ea37

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,46 @@ function pad(num) {
33
}
44

55
function formatTimeDisplay(seconds) {
6-
const remainingSeconds = seconds % 60;
6+
const remainingSeconds = seconds % 60;
7+
//get the remaining seconds after dividing by 61/60 = 1 remainder 1
78
const totalMinutes = (seconds - remainingSeconds) / 60;
9+
//get seconds = 1 - 60; result is 60/60 = total minutes 1
810
const remainingMinutes = totalMinutes % 60;
11+
//the remainingMinutes = 1 & 60 = 1; because the totalMinutes is less than
12+
// 60 the number will always the number from left side of the modulus operator
913
const totalHours = (totalMinutes - remainingMinutes) / 60;
1014

1115
return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`;
1216
}
1317

18+
19+
console.log(formatTimeDisplay(61)); // Should print "00:01:01"
20+
1421
// You will need to play computer with this example - use the Python Visualiser https://pythontutor.com/visualize.html#mode=edit
1522
// to help you answer these questions
1623

1724
// Questions
1825

1926
// a) When formatTimeDisplay is called how many times will pad be called?
2027
// =============> write your answer here
28+
// pad function will be called 3 times when formatTimeDisplay is called.
2129

22-
// Call formatTimeDisplay with an input of 61, now answer the following:
30+
//==== Call formatTimeDisplay with an input of 61, now answer the following:
2331

2432
// b) What is the value assigned to num when pad is called for the first time?
25-
// =============> write your answer here
33+
// =============> write your answer here
34+
// The value assigned to num when pad is called for the first time is 0.
2635

2736
// c) What is the return value of pad is called for the first time?
2837
// =============> write your answer here
38+
// The return value of pad when it is called for the first time is "00".
39+
// because num is 0, and when we convert it to a string and pad it to 2
40+
// characters with leading zeros, it becomes "00".
2941

3042
// d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer
3143
// =============> write your answer here
44+
// The value assigned to num when pad is called for the last time in this program is 1
3245

3346
// e) What is the return value assigned to num when pad is called for the last time in this program? Explain your answer
3447
// =============> write your answer here
48+
// The return value assigned to num when pad is called for the last time in this program is "01".

0 commit comments

Comments
 (0)