Skip to content

Commit 4f61c5c

Browse files
committed
Answered questions relating to time-format.js
used console.log to help understand how the function works.
1 parent 82e81ed commit 4f61c5c

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,52 @@
1+
console.log("entered data")
12
function pad(num) {
3+
console.log("pad has been called: Num is", num);
24
let numString = num.toString();
35
while (numString.length < 2) {
46
numString = "0" + numString;
57
}
8+
console.log("numString: ", numString);
69
return numString;
710
}
811

912
function formatTimeDisplay(seconds) {
13+
console.log("entered formatTimeDisplay");
1014
const remainingSeconds = seconds % 60;
15+
console.log("remainingSeconds: ", remainingSeconds);
1116
const totalMinutes = (seconds - remainingSeconds) / 60;
17+
console.log("totalMinutes: ", totalMinutes);
1218
const remainingMinutes = totalMinutes % 60;
19+
console.log("remainingMinutes: ", remainingMinutes);
1320
const totalHours = (totalMinutes - remainingMinutes) / 60;
21+
console.log("totalHours: ", totalHours);
22+
1423

1524
return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`;
1625
}
17-
26+
console.log(formatTimeDisplay(61))
1827
// You will need to play computer with this example - use the Python Visualiser https://pythontutor.com/visualize.html#mode=edit
1928
// to help you answer these questions
2029

2130
// Questions
2231

2332
// a) When formatTimeDisplay is called how many times will pad be called?
2433
// =============> write your answer here
34+
// Pad is being called 3 times
2535

2636
// Call formatTimeDisplay with an input of 61, now answer the following:
2737

2838
// b) What is the value assigned to num when pad is called for the first time?
2939
// =============> write your answer here
40+
// 0
3041

3142
// c) What is the return value of pad when it is called for the first time?
3243
// =============> write your answer here
44+
// 00
3345

3446
// d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer
3547
// =============> write your answer here
48+
// 1, The value given is the remainder after being used in remainingMinutes section of the code
3649

3750
// e) What is the return value of pad when it is called for the last time in this program? Explain your answer
3851
// =============> write your answer here
52+
// 01, after going through pad it ensures that there is two 00 if there is no value left, with just 1 it adds one 0 to the front of 1.

0 commit comments

Comments
 (0)