@@ -11,15 +11,57 @@ console.log(result);
1111
1212// For the piece of code above, read the code and then answer the following questions
1313
14+
15+
1416// a) How many variable declarations are there in this program?
17+ /************************************************** */
18+ /* Solution a): There are 6 varibale declarations */
19+ /************************************************* */
20+
1521
1622// b) How many function calls are there?
23+ /**************************************************/
24+ /* Solution b): */
25+ /* There is only one fuction call (console.log() */
26+ /*********************************************** */
1727
1828// c) Using documentation, explain what the expression movieLength % 60 represents
1929// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
2030
31+ /*********************************************************************************************************************/
32+ /*Solution c): */
33+ /* The operator (%) called Modulo returns the remainder left over when one operand is divided by a second operand */
34+ /* In this expamle it gives the time remainder of the movie in seconds */
35+ /*********************************************************************************************************************/
36+
37+
38+
2139// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
2240
41+ /****************************************************************************************************************************************************************************/
42+ /* Solution d): */
43+ /* The totalMinutes expression is calaculated first by subtrackting the lengh of movie by the reminder of seconds which rounds down the nearst minutes */
44+ /* Since we know the total number of seconds that are multiple of 60 we can can calculate the total number of minutes by dividing it over 60 since 1 minute is 60 seconds */
45+ /* This way we have the Movie total exact number of miutes. */
46+ /****************************************************************************************************************************************************************************/
47+
48+
2349// e) What do you think the variable result represents? Can you think of a better name for this variable?
50+ /*********************************************************************************************/
51+ /* Solution e): */
52+ /* The variable result represents the exact lenght of the movie in Hours + Minutes + Seconds */
53+ /* A better name for variable result could be : extctMovieLength */
54+ /*********************************************************************************************/
2455
2556// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
57+
58+ /***************************************************************************************************************************************************************/
59+ /* Solution e): */
60+ /* movieLength = 0 => exactMovieLength = 0:0:0 */
61+ /* movieLength = 60 => exactMovieLength = 0:1:0 */
62+ /* movieLength = 3676 => exactMovieLength = 1:1:16 */
63+ /* */
64+ /* This code work for all values of movieLength provided that it doesn't exeed 86400 which is 24 hours = 1 day (realisticly no movie is over 24 hours) */
65+ /* */
66+ /**********************************************************************************************************************************************************/
67+
0 commit comments