Skip to content

Commit a6d27f3

Browse files
answered questions on comments for clarity on variable declarations and calculations in time format code
1 parent 1dd8029 commit a6d27f3

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,21 @@ 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+
// Answer: they are 5 variable declarations which are all defined by using const variable.
16+
// they are movieLength, remainingSeconds, totalMinutes, remainingMinutes, and result.
1517

1618
// b) How many function calls are there?
19+
// Answer: there are no function calls in this program all the code is just variable declarations and assignments.
1720

1821
// c) Using documentation, explain what the expression movieLength % 60 represents
22+
// Answer: The expression `movieLength % 60` calculates the remainder when `movieLength` is divided by 60. this is whats used to find the remaining seconds after converting the total movie length from seconds to minutes.
1923
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
2024

2125
// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
26+
// Answer: The expression "(movieLength - remainingSeconds) / 60" calculates the total number of minutes in the movie by first subtracting the remaining seconds from the total movie length in seconds and then dividing that result by 60 to convert seconds to minutes. This gives us the total minutes of the movie excluding the remaining seconds.
2227

2328
// e) What do you think the variable result represents? Can you think of a better name for this variable?
29+
// Answer: The variable "result" represents the formatted time of the movie in the format "hours:minutes:seconds". A better name for this variable could be "formattedRuntime" to make it clearer that it holds the duration of the movie in a readable format.
2430

2531
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
32+
// Answer: Yes this would work for all different values of "movieLength" as long as the value is a non-negative integer. The code correctly calculates the hours, minutes, and seconds regardless of the total length of the movie in seconds. If the value of "movieLength" is negative it would still work but would yield a negative time format which may not make sense in a real-world context and produce errors.

0 commit comments

Comments
 (0)