Skip to content

Commit 705d9fb

Browse files
answered the questions
1 parent 122b382 commit 705d9fb

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

Sprint-1/3-mandatory-interpret/2-time-format.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const movieLength = 8784; // length of movie in seconds
1+
const movieLength = 15560; // length of movie in seconds
22

33
const remainingSeconds = movieLength % 60;
44
const totalMinutes = (movieLength - remainingSeconds) / 60;
@@ -12,14 +12,27 @@ 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 - remainingSeconds, totalMinutes, remainingMinutes,
16+
// totalHours, result and movieLength
1517

1618
// b) How many function calls are there?
19+
// there is 1 function call - console.log is called on the last line to print the result to the console
1720

1821
// c) Using documentation, explain what the expression movieLength % 60 represents
1922
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
23+
// It is counting the remaining seconds after all the full minutes have been taken out of the movie length.
24+
// For example if the movie length is 125 seconds, then 125 % 60 would give us 5 seconds remaining after taking out the full minutes (2 minutes in this case).
2025

2126
// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
27+
// The expression (movieLength - remainingSeconds) / 60 calculates the total number of minutes in the movie length.
28+
// It subtracts the remaining seconds from the total seconds and then divides by 60 to get the total minutes.
2229

2330
// e) What do you think the variable result represents? Can you think of a better name for this variable?
31+
// result gives the length of the movie in hours, minutes and seonds
32+
// a better name may be movieLengthFormatted or something similar
2433

2534
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
35+
// Yes, this code will work for all values of movieLength
36+
//%60 gives the remainder and the remainder is always taken away before dividing for minutes and hours
37+
// so it will always give the correct number of hours, minutes and seconds regardless of the length of
38+
// the movie in seconds.

0 commit comments

Comments
 (0)