|
1 | | -const movieLength = 6; // length of movie in seconds |
| 1 | +const movieLength = 3540; // length of movie in seconds |
2 | 2 |
|
3 | 3 | const remainingSeconds = movieLength % 60; |
4 | 4 | const totalMinutes = (movieLength - remainingSeconds) / 60; |
5 | 5 |
|
6 | 6 | const remainingMinutes = totalMinutes % 60; |
7 | 7 | const totalHours = (totalMinutes - remainingMinutes) / 60; |
8 | 8 |
|
9 | | -const result = `${totalHours}:${remainingMinutes}:${remainingSeconds}`; |
10 | | -console.log(result); |
| 9 | +const formattedtime = `${totalHours}:${remainingMinutes}:${remainingSeconds}`; |
| 10 | +console.log(formattedtime); |
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 | | -//6 |
| 15 | +6 |
16 | 16 | // b) How many function calls are there? |
17 | | -//1 |
| 17 | +1 |
18 | 18 | // c) Using documentation, explain what the expression movieLength % 60 represents |
19 | 19 | // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators |
20 | 20 |
|
21 | | -//It divides totalMinutes into 60, see how much remainingMinutes left. |
| 21 | +It divides totalMinutes into 60, see how much remainingMinutes left. |
22 | 22 |
|
23 | 23 | // d) Interpret line 4, what does the expression assigned to totalMinutes mean? |
24 | | -//After deducting the totalMinutes, and divide the second. How much do he have the totalMinutes ? |
| 24 | +After deducting the totalMinutes, and divide the second. How much do he have the totalMinutes ? |
25 | 25 |
|
26 | 26 | // e) What do you think the variable result represents? Can you think of a better name for this variable? |
27 | | -//The total duration of the movieLength. |
| 27 | + We can use formmattedtime to point out the time has been formatted. |
28 | 28 |
|
29 | | -// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer |
30 | | -//for one hour = 3600 minutes . 1:00:00 |
31 | | -//for 59 minutes = 3540 minutes . 0:59:0 |
32 | | -//for seconds = 6 seconds . 0:0:6 |
| 29 | + // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer |
| 30 | +for one hour = 3600 second . 1:00:00. No, it does not work here, because the remaining minutes and second forgets the extra zero. |
| 31 | + |
| 32 | +//for 59 minutes = 3540 second . 0:59:0 No, it does not work here, because the remaining seconds and total hour forgets the extra zero. |
| 33 | +for seconds = 6 seconds . 0:0:6. No, it does not work here, because the totalHours, remainingMinutes and remaining seconds forgets the extra zero. |
0 commit comments