@@ -6,7 +6,9 @@ const totalMinutes = (movieLength - remainingSeconds) / 60;
6
6
const remainingMinutes = totalMinutes % 60 ;
7
7
const totalHours = ( totalMinutes - remainingMinutes ) / 60 ;
8
8
9
- const result = `${ totalHours } :${ remainingMinutes } :${ remainingSeconds } ` ;
9
+ const result = `${ String ( totalHours ) . padStart ( 2 , "0" ) } :${ String (
10
+ remainingMinutes
11
+ ) . padStart ( 2 , "0" ) } :${ String ( remainingSeconds ) . padStart ( 2 , "0" ) } `;
10
12
console . log ( result ) ;
11
13
12
14
// For the piece of code above, read the code and then answer the following questions
@@ -15,7 +17,7 @@ console.log(result);
15
17
// there are 6 variable declarations in this program. They are on lines 1, 3, 4, 6, 7 and 9
16
18
17
19
// b) How many function calls are there?
18
- // there are 2 function calls in this program. They are on lines 9 and 10
20
+ // there is 1 function calls in this program. And it is on line 10
19
21
20
22
// c) Using documentation, explain what the expression movieLength % 60 represents
21
23
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
@@ -27,7 +29,7 @@ seconds and then dividing that result by 60.*/
27
29
28
30
// e) What do you think the variable result represents? Can you think of a better name for this variable?
29
31
/* the variable result represents the total length of the movie in hours, minutes and seconds. A better name for this variable could
30
- be movieDuration .*/
32
+ be formattedmovieDuration .*/
31
33
32
34
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
33
35
// yes this code will work for all values of movieLength as long as the value is a non-negative integer representing the length of a movie in seconds.
0 commit comments