@@ -12,14 +12,25 @@ 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.
1516
1617// b) How many function calls are there?
18+ // There is 1 function call, which is 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+ // % is Remainder operator. In this case, movieLength % 60 gives us the number of seconds
23+ // that are left after we have taken out all the full minutes from the movie length.
2024
2125// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
26+ // calculates the total number of minutes in the movie length,
27+ // excluding the remaining seconds that are less than a full minute.
2228
2329// e) What do you think the variable result represents? Can you think of a better name for this variable?
30+ // The variable result represents the formatted time in hours, minutes, and seconds.
31+ // A better name for this variable could be movieFormattedTime.
2432
2533// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
34+ // This code will work for all non-negative integer values of movieLength.
35+ // However, if movieLength is a negative number, the result will be weird format with negative numbers.
36+ // Moreover, if movieLength is not an integer, the result will also be weird format with decimal numbers.
0 commit comments