@@ -12,14 +12,29 @@ 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 this program on lines 1, 3, 4, 6, 7, 9.
1516
1617// b) How many function calls are there?
18+ // 1: console.log() on line 10.
1719
1820// c) Using documentation, explain what the expression movieLength % 60 represents
21+ // The remainder (%) operator returns the remainder left over when one operand (dividend) is divided by a second operand (divisor).
22+ // It always takes the sign (+/-) of the dividend (the first number).
23+ // So the movie length in seconds is divided by 60 (the number of seconds in a minute).
24+ // The remainder is the number of seconds left over after all the full minutes have been accounted for.
1925// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
2026
2127// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
28+ // It subtracts the remaining seconds from total movie length to get the total length in seconds that can be evenly divided by 60.
29+ // Then divides by 60 to convert the length from seconds to minutes.
30+ // So totalMinutes represents the total number of full 60-second minutes in the movie.
2231
2332// e) What do you think the variable result represents? Can you think of a better name for this variable?
33+ // The variable result represents the total length of the movie in hours, minutes and seconds.
34+ // A better name for this variable could be movieDuration or movieFormattedLength.
2435
2536// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
37+ // The code will work for all positive integer values of movieLength formatting to H:MM:SS
38+ // It will also work for 0, returning 0:0:0
39+ // It will incorrectly format negative numbers and very small number like < 60 seconds.
40+ // Single digit minutes and seconds will not be zero-padded to two digits e.g. String(remainingMinutes).padStart(2, "0")
0 commit comments