@@ -12,14 +12,26 @@ 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+ // 6 declarations: movieLength, remainingSeconds, totalMinutes, remainingMinutes, totalHours, result
1516
1617// b) How many function calls are there?
18+ // 1 function call: console.log(result)
1719
1820// c) Using documentation, explain what the expression movieLength % 60 represents
19- // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
21+ // % is the remainder operator - calculates remainder when dividing movieLength by 60
22+ // Example: 8784 % 60 = 24 (seconds that don't fit into complete minutes)
23+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Remainder
2024
2125// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
26+ // (movieLength - remainingSeconds) / 60 calculates complete minutes
27+ // Subtracts leftover seconds (24) from total (8784), then divides by 60 to convert to minutes
2228
2329// e) What do you think the variable result represents? Can you think of a better name for this variable?
30+ // Represents movie length formatted as "hours:minutes:seconds"
31+ // Better names: formattedTime, timeString, movieDuration, formattedDuration
2432
2533// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
34+ // Works mathematically for positive integers but has formatting issues:
35+ // - Single digits aren't zero-padded (shows "1:6:5" instead of "01:06:05")
36+ // - Negative values produce incorrect results
37+ // - Would need padStart() for proper time formatting
0 commit comments