Skip to content

Commit 376454f

Browse files
committed
Completed tasks a-f with explanations and test analysis
1 parent d29e07d commit 376454f

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,33 @@ 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+
// movieLength, remainingSeconds, totalMinutes, remainingMinutes, totalHours, result
16+
// Answer: Each uses const, so each counts as a declaration. There are 6 variable declarations in total.
1517

1618
// b) How many function calls are there?
19+
// console.log(result)
20+
// Answer: There is 1 function call in this program. Everything else is arithmetic, not a function call.
1721

1822
// c) Using documentation, explain what the expression movieLength % 60 represents
1923
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
24+
// According to the documentation, the remainder operator (%) returns the remainder after dividing one number by another.
25+
// In this case, movieLength % 60 divides movieLength (which is in seconds) by 60,
26+
// returns the leftover seconds that don't fit into a full minute.
2027

2128
// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
29+
// This line removes the leftover seconds (remainingSeconds) and converts the remaining whole seconds into minutes.
30+
// So it gives you the total number of whole minutes in the movie.
2231

2332
// e) What do you think the variable result represents? Can you think of a better name for this variable?
33+
// The result variable represents the final formatted time of the movie in hours, minutes and seconds.
34+
// hours:minutes:seconds format. A better name could be formattedTime or movieDuration.
2435

2536
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
37+
// If I set movieLength to 8784, the output will be "2:26:24", which is correct,
38+
// so this is a normal case where the code works as expected.
39+
40+
// If I set movieLength to 0, the output will be "0:0:0", which is also correct,
41+
// shows it can handle edge cases even though it is an unusual value.
42+
43+
// If I set movieLength to -200, the output will be "-1:-3:-20", which is not a valid time format,
44+
// shows that the logic breaks because the code does not protect against invalid negative inputs.

0 commit comments

Comments
 (0)