@@ -12,14 +12,31 @@ 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+ // There are 6 variable declarations in total: movieLength, remainingSeconds, totalMinutes, remainingMinutes, totalHours, result
1516
1617// b) How many function calls are there?
18+ // T There is 1 function call in this program: console.log(result)
1719
1820// c) Using documentation, explain what the expression movieLength % 60 represents
1921// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
22+ // According to the documentation, the remainder operator (%) returns the remainder after dividing one number by another.
23+ // In this case, movieLength % 60 divides movieLength (which is in seconds) by 60,
24+ // And returns the leftover seconds that don't fit into a full minute.
2025
2126// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
27+ // This line removes the leftover seconds (remainingSeconds) and converts the remaining whole seconds into minutes.
28+ // So it gives you the total number of whole minutes in the movie.
2229
2330// e) What do you think the variable result represents? Can you think of a better name for this variable?
31+ // The result variable represents the final formatted time of the movie in hours, minutes and seconds - hours:minutes:seconds format.
32+ // A better name could be formattedTime or movieDuration.
2433
2534// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
35+ // If I set movieLength to 8784, the output will be "2:26:24", which is correct,
36+ // so this is a normal case where the code works as expected.
37+
38+ // If I set movieLength to 0, the output will be "0:0:0", which is also correct,
39+ // It shows it can handle edge cases even though it is an unusual value.
40+
41+ // If I set movieLength to -200, the output will be "-1:-3:-20", which is not a valid time format,
42+ // This shows that the logic breaks because the code does not protect against invalid negative inputs.
0 commit comments