@@ -12,14 +12,36 @@ 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+ there are 6 variable declarations in this programe they are in the following lines :
16+
17+ const movieLength = 8784 ; // length of movie in seconds
18+
19+ const remainingSeconds = movieLength % 60 ;
20+ const totalMinutes = ( movieLength - remainingSeconds ) / 60 ;
21+
22+ const remainingMinutes = totalMinutes % 60 ;
23+ const totalHours = ( totalMinutes - remainingMinutes ) / 60 ;
24+
25+ const result = `${ totalHours } :${ remainingMinutes } :${ remainingSeconds } ` ;
1526
1627// b) How many function calls are there?
28+ there is 1 function call in this program and it is in the following line :
29+
30+ console . log ( result ) ;
1731
1832// c) Using documentation, explain what the expression movieLength % 60 represents
19- // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
33+ https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
34+
35+ The expression `movieLength % 60` calculates the remainder when `movieLength` is divided by 60.
36+ In this context , it gives the number of seconds that remain after converting the total seconds into minutes and hours .
2037
2138// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
39+ The expression assigned to `totalMinutes` calculates the total number of minutes in `movieLength`
40+ by subtracting the remaining seconds and dividing by 60.
41+
2242
2343// e) What do you think the variable result represents? Can you think of a better name for this variable?
44+ variable result represents the formatted time in hours , minutes , and seconds ( HH :MM :SS ) .
2445
2546// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
47+ yes this code will work for all values of movieLength asa long as it is a non - negative integers .
0 commit comments