Skip to content

Commit bb34ab4

Browse files
- verify variable declaration and function call count
- document and explain the remainder(%) operator to calculate the remaining seconds after converting total seconds into full minutes. - provide a better name for the variable 'result' and experiment with different values of movieLength
1 parent 4922e00 commit bb34ab4

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,28 @@ console.log(result);
1212
// For the piece of code above, read the code and then answer the following questions
1313

1414
// a) How many variable declarations are there in this program?
15+
// ANSWER: There are 6 variable declarations.
16+
// (movieLength, remainingSeconds, totalMinutes, remainingMinutes, totalHours, and result — all declared using const)
1517

1618
// b) How many function calls are there?
19+
// ANSWER: There is only function call
20+
// console.log(result)
1721

1822
// c) Using documentation, explain what the expression movieLength % 60 represents
1923
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
2024

25+
//ANSWER: The expression movieLength % 60 uses the remainder (%) operator to calculate the number of seconds remaining that can't form a full seconds (8784 % 60 = 24 seconds)
26+
27+
// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
28+
// ANSWER: The expression assigned to totalMinutes means division
29+
2130
// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
31+
// ANSWER: It subtracts the remainder seconds from movieLength to get an exact multiple of 60, then divides by 60 to convert the seconds into whole minutes (146 minutes).
2232

2333
// e) What do you think the variable result represents? Can you think of a better name for this variable?
34+
// ANSWER: A better name for the variable would be 'formattedDuration' because it clearly describes that the variable stores the movie duration in a formatted hours, minutes, and seconds format.
2435

2536
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
37+
38+
// ANSWER: No. It breaks if movieLength is negative (giving negative time) or a string.
39+
// Additionally, single-digit minutes or seconds (e.g., 4 minutes, 8 seconds) output as "2:4:8" instead of standard "02:04:08" formatting.

0 commit comments

Comments
 (0)