11const movieLength = 8784 ; // length of movie in seconds
22
33const remainingSeconds = movieLength % 60 ;
4+ console . log ( remainingSeconds )
45const totalMinutes = ( movieLength - remainingSeconds ) / 60 ;
56
67const remainingMinutes = totalMinutes % 60 ;
@@ -12,14 +13,26 @@ console.log(result);
1213// For the piece of code above, read the code and then answer the following questions
1314
1415// a) How many variable declarations are there in this program?
16+ // There are 6 variable declarations
17+
1518
1619// b) How many function calls are there?
20+ // There are no function calls.
21+
1722
1823// c) Using documentation, explain what the expression movieLength % 60 represents
1924// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
25+ // The expression return the reminder from movieLength % 60. In this case returns the number of seconds left which is 24.
26+
2027
2128// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
29+ // the expression evaluates to total number of movie minutes by subtracting the number of seconds.
30+
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 represent the duration of thr movie in hours,minutes and seconds.
34+ // A better name fot this variable is movieDuration
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 the values of movieLength. But if we use negative numbers ut will gie us an invalid duration.
38+ // Ex movieLength = -8784 movieDuration = -2: -26: -24
0 commit comments