1- const movieLength = 8784 ; // length of movie in seconds
1+ const movieLength = 5.345345 ; // length of movie in seconds
22
33const remainingSeconds = movieLength % 60 ;
44const totalMinutes = ( movieLength - remainingSeconds ) / 60 ;
@@ -13,13 +13,35 @@ console.log(result);
1313
1414// a) How many variable declarations are there in this program?
1515
16+ // 6
17+
1618// b) How many function calls are there?
1719
20+ // 1
21+
1822// c) Using documentation, explain what the expression movieLength % 60 represents
1923// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
2024
25+ // % is a modulus operator
26+ // It acts as a divisor, but instead of returning the resultant division, it returns the remainder
27+ // So movieLength % 60 divides the movieLength into whole minutes and returns however many seconds remain
28+
2129// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
2230
31+ // It is giving the total number of minutes of the movieLength to the nearest whole number (rounded down)
32+ // It does this by finding removing the remainder of seconds from the total movie length to give the largest
33+ // movieLength in seconds that is still exactly divisible by 60, then dividing by 60 to give it in minutes
34+
2335// e) What do you think the variable result represents? Can you think of a better name for this variable?
2436
37+ // It looks to return a string that breaks the movie length into hours, minutes and seconds that is easier to read/understand
38+ // (at least for a human)
39+ // a better variable name may be something like formattedTime
40+
2541// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
42+
43+ // Yes
44+ // The code is using basic mathematical operators, it works even with extremely small or large numbers, it works with 0, it even
45+ // works with negative numbers, although that is a little nonsensical, it may be better to return an error or undefined in that case
46+ // For very large numbers it would return a high number of hours, which one may want to then convert to days, or have a max limit
47+ // It all depends on what the use case for the code is
0 commit comments