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
// The expression movieLength % 60 uses the modulo (%) operator to find the remainder after dividing movieLength by 60. This gives the number of seconds left over after converting all full minutes from the total seconds.
20
20
21
21
// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
22
+
// The expression (movieLength - remainingSeconds) / 60 converts the total number of seconds (minus any leftover seconds) into full minutes, effectively giving the total number of complete minutes in the movie.
22
23
23
24
// e) What do you think the variable result represents? Can you think of a better name for this variable?
25
+
// The variable result represents the movie length converted from seconds into hours, minutes, and seconds in the format "hours:minutes:seconds". A better name for this variable would be formattedDuration or timeString for clarity.
24
26
25
27
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
28
+
// This code works correctly for positive integer values of movieLength because it cleanly divides seconds into hours, minutes, and seconds. However, it will not work properly for negative numbers or non-integer values, and it doesn’t add leading zeros (e.g. it might print 2:5:3 instead of 2:05:03).
0 commit comments