@@ -12,14 +12,20 @@ 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-
15+ 6 variable Declarations , every const creates a new variable .
1616// b) How many function calls are there?
17-
17+ 1 function calls is console . log ( ) as it is a function being called and told to do the job
1818// c) Using documentation, explain what the expression movieLength % 60 represents
1919// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
2020
21- // d) Interpret line 4, what does the expression assigned to totalMinutes mean?
21+ movieLength % 60 means finding the remainder after dividing movieLength by 60. movieLength = 8784 so we need to do : 8784 % 60 = 146.4 and the nearest whole integer is 146.
22+ So there are 146 complete groups of 60. we then multiply ; 146 x 60 = 8760 -- > 8784 - 8760 = 24 so 8784 % 60 = 24 and therefore remainingSeconds becomes 24.
2223
24+ // d) Interpret line 4, what does the expression assigned to totalMinutes mean?
25+ const totalMinutes = ( movieLength - remainingSeconds ) / 60 -- - > if we break it down - > movieLength = 8784 remainingSeconds = 24
26+ we then subtract remainingSeconds from movieLength = 8784 - 24 = 8670. we then have to divide it by 60 which gives us 8760 / 60 = 146. we divide because there is 60 seconds in one minute , and right now we are converting seconds into minutes .
2327// e) What do you think the variable result represents? Can you think of a better name for this variable?
24-
28+ The result variable will show us he complete results from our calculations of = totalHours :remainingMinutes :remainingSeconds .
29+ result = 2 :26 :24
2530// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
31+ I tested differnet codes : 7965 and I got the result 2 :12 :45 and i also tried : 2654 and got 0 :44 :14.
0 commit comments