|
1 | | -const movieLength = 8784; // length of movie in seconds |
| 1 | +// const movieLength = 8784; // length of movie in seconds |
2 | 2 |
|
3 | | -const remainingSeconds = movieLength % 60; |
4 | | -const totalMinutes = (movieLength - remainingSeconds) / 60; |
| 3 | +// const remainingSeconds = movieLength % 60; |
| 4 | +// const totalMinutes = (movieLength - remainingSeconds) / 60; |
5 | 5 |
|
6 | | -const remainingMinutes = totalMinutes % 60; |
7 | | -const totalHours = (totalMinutes - remainingMinutes) / 60; |
| 6 | +// const remainingMinutes = totalMinutes % 60; |
| 7 | +// const totalHours = (totalMinutes - remainingMinutes) / 60; |
8 | 8 |
|
9 | | -const result = `${totalHours}:${remainingMinutes}:${remainingSeconds}`; |
10 | | -console.log(result); |
| 9 | +// const result = `${totalHours}:${remainingMinutes}:${remainingSeconds}`; |
| 10 | +// console.log(result); |
11 | 11 |
|
12 | 12 | // For the piece of code above, read the code and then answer the following questions |
13 | 13 |
|
14 | 14 | // a) How many variable declarations are there in this program? |
| 15 | + // There are 6 variable declarations, lines 1,3,4,6,7,9 |
15 | 16 |
|
16 | 17 | // b) How many function calls are there? |
| 18 | + //1 at line 10 |
17 | 19 |
|
18 | 20 | // c) Using documentation, explain what the expression movieLength % 60 represents |
19 | 21 | // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators |
| 22 | + //This is using a remainder, this us seeing how many times 8784 goes into 60 and what is remaining which is 24 in this case: |
| 23 | + // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Remainder |
20 | 24 |
|
21 | 25 | // d) Interpret line 4, what does the expression assigned to totalMinutes mean? |
| 26 | + // It is the sum of movieLength minus remainingSeconds then divided by 60 |
22 | 27 |
|
23 | 28 | // e) What do you think the variable result represents? Can you think of a better name for this variable? |
| 29 | + // its showing the length of the movie in hours, minutes and seconds, could be better called something like MovieDuration |
24 | 30 |
|
25 | 31 | // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer |
| 32 | + //Yes it will as long as the input is numerical numbers only, it does not work with any extra symbols, spaces or letters. |
0 commit comments