1- const movieLength = 8784 ; // length of movie in seconds
1+ const movieLength = 8784 ; // length of movie in seconds 8784
22
33const remainingSeconds = movieLength % 60 ;
4+ console . log ( remainingSeconds ) ;
5+
46const totalMinutes = ( movieLength - remainingSeconds ) / 60 ;
7+ console . log ( totalMinutes ) ;
58
69const remainingMinutes = totalMinutes % 60 ;
10+ console . log ( remainingMinutes ) ;
11+
12+
713const totalHours = ( totalMinutes - remainingMinutes ) / 60 ;
814
915const result = `${ totalHours } :${ remainingMinutes } :${ remainingSeconds } ` ;
1016console . log ( result ) ;
1117
12- // For the piece of code above, read the code and then answer the following questions
18+ /*
19+ For the piece of code above, read the code and then answer the following questions
20+
21+ a) How many variable declarations are there in this program?
22+
23+ -------- 6 in total
24+ -------- movieLength - declared as const
25+ -------- remainingSeconds - declared as const
26+ -------- totalMinutes - declared as const
27+ -------- remainingMinutes - declared as const
28+ -------- totalHours - declared as const
29+ -------- result - declared as const
30+
31+
32+ b) How many function calls are there?
33+
34+ -------- console.log(result);
35+
36+ c) Using documentation, explain what the expression movieLength % 60 represents
37+
38+ -------- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Remainder
39+ -------- Remainder:
40+ -------- WITH % we can obtain the remainder between the var movieLength % 60; and stored in remainingMinutes
1341
14- // a) How many variable declarations are there in this program ?
42+ d) Interpret line 4, what does the expression assigned to totalMinutes mean ?
1543
16- // b) How many function calls are there?
44+ -------- This line is taking the leftover remainder in remainingMinutes and leaving just the
45+ total amount that we can divide perfectly in whole number to see how many minutes we have.
1746
18- // c) Using documentation, explain what the expression movieLength % 60 represents
47+ e) What do you think the variable result represents? Can you think of a better name for this variable?
1948
20- // d) Interpret line 4, what does the expression assigned to totalMinutes mean?
49+ ------- Result var represent the total runtime of the movie, the nameVar is fine but we can name it as
50+ timeMovie for better readability, as it gives future readers a better idea of the variable's purpose.
2151
22- // e) What do you think the variable result represents? Can you think of a better name for this variable?
52+ f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
2353
24- // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
54+ ------- This code works as expected for the most of positive values of movieLength. Just
55+ when I write negative number in the result will show the negative sign. eg.
56+ const movieLength = -4258;
57+ result: -1:-10:-58
58+ */
0 commit comments