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 remainder operator ( % ) to work out how many seconds are left over after dividing the total movie length by 60.
23
+
// So if movieLength is 8784 seconds, dividing by 60 gives 146 full minutes with 24 seconds left - that leftover part (24) is what this expression returns.
24
+
// According to MDN Docs, the remainder operator gives the value that's left after one number is divided by another
20
25
21
26
// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
27
+
// The expression totalMinutes is a variable that stores the result of the calculation (movieLength - remainingSeconds) / 60. It represents the total number of full minutes in the movie after converting the total seconds into minutes.
28
+
// According to MDN Docs, a variable is a named container used to store data values. In this cause, totalMinutes holds a numeric value that JavaScript can use later in other calculations, like finding the number of hours or remaining minutes.
22
29
23
30
// e) What do you think the variable result represents? Can you think of a better name for this variable?
31
+
// The variable result stores a formatted string that combines the total hours, remaining minutes, and remaining seconds into one readable time format.
32
+
// It uses template literals (the backtick syntax `...`) to insert each variable's value directly into the string using ${} placeholders.
33
+
// so, for example, if totalHours = 2, remainingMinutes = 26, and remainingSeconds = 24, the value of result becomes the string "2 : 26 : 24".
34
+
// According to MDN Docs, template literals allow embedded expressions inside strings, making it easier to create dynamic text
35
+
// A better name for the variable result would be formattedTime because it makes it clearer what the value actually represents. Moreover, using a name like formattedTime makes the code easier to read and understand
24
36
25
37
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
38
+
// This code works properly for positive whole numbers because the reminder ( % ) and division ( / ) operators correctly split the total number of seconds into hours, minutes, and seconds.
39
+
// However, it might not give the right results if movieLength is negative, a decimal, or not a number at all. As explained on MDN Docs, the remainder operator keeps the same sign as the left number, so if the input is negative, you would get negative remainders - which wouldn't make sense when showing time
0 commit comments