You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- 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
//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
+
21
30
// 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).
22
32
23
33
// 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.
24
35
25
36
// 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