Skip to content

Commit ee63ed9

Browse files
committed
completed scheduled tasks
1 parent a36e160 commit ee63ed9

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

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

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,34 @@ 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-
15+
/*
16+
There are 6 variable declarations in this program.
17+
They are on the following lines:
18+
Line 1: const movieLength = 8784; // length of movie in seconds
19+
Line 3: const remainingSeconds = movieLength % 60;
20+
Line 4: const totalMinutes = (movieLength - remainingSeconds) / 60;
21+
Line 6: const remainingMinutes = totalMinutes % 60;
22+
Line 7: const totalHours = (totalMinutes - remainingMinutes) / 60;
23+
Line 9: const result = `${totalHours}:${remainingMinutes}:${remainingSeconds}`;
24+
*/
1625
// b) How many function calls are there?
26+
/*
27+
There is 1 function call in this program.
28+
It is on the following line:
29+
Line 10: console.log(result);
30+
*/
31+
32+
// Consider: Why do we say this is a function call? What is being passed to the function as an argument?
33+
/*
34+
A function call is when a function is invoked or executed. In this case, the function being called is console.log, which is a built-in function in JavaScript that outputs a message to the console. The argument being passed to the function is the variable 'result', which contains the formatted string representing the movie length in hours, minutes, and seconds.
35+
The value being passed to the console.log() function as an argument is the final calculated and formatted string stored in the result variable.
36+
*/
1737

1838
// c) Using documentation, explain what the expression movieLength % 60 represents
1939
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
20-
40+
// The expression movieLength % 60 calculates the remainder when the value of movieLength (which is in seconds) is divided by 60. This operation is known as the modulus operator (%). In this context, it is used to determine the number of seconds that are left over after converting the total movie length into full minutes. Since there are 60 seconds in a minute, this expression effectively gives us the remaining seconds that do not make up a full minute.
2141
// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
22-
42+
// The expression assigned to totalMinutes is (movieLength - remainingSeconds) / 60. This expression first subtracts the remaining seconds (calculated in line 3) from the total movie length in seconds (movieLength). This gives the total number of seconds that can be fully converted into minutes. Then, this result is divided by 60, since there are 60 seconds in a minute. The final result is the total number of full minutes in the movie length, excluding any leftover seconds.
2343
// e) What do you think the variable result represents? Can you think of a better name for this variable?
24-
44+
// The variable result represents the formatted string that shows the movie length in hours, minutes, and seconds. A better name for this variable could be formattedMovieLength or movieDurationFormatted, as these names more clearly indicate that the variable contains a formatted representation of the movie's duration.
2545
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer

0 commit comments

Comments
 (0)