Skip to content

Commit bec2478

Browse files
committed
Redesign the explanation
1 parent 044b702 commit bec2478

File tree

1 file changed

+16
-29
lines changed

1 file changed

+16
-29
lines changed

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

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -26,65 +26,52 @@ console.log(result);
2626

2727
// The only function call is:
2828

29-
// Total function calls: 1
29+
// Total function call is 1
3030
// console.log(result);
3131

3232
// c) Using documentation, explain what the expression movieLength % 60 represents
3333
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
3434

3535
// According to the MDN documentation on the remainder (%) operator
36-
// The remainder operator returns the remainder left over when one operand is divided by a second operand.
37-
// So:
38-
// movieLength % 60
39-
// means “the remainder when movieLength is divided by 60.”
36+
// The variable remainingSeconds stores the remainder left over when one movieLength operand is divided by 60
37+
4038
// Interpretation:
41-
// It gives you the remaining seconds that don’t make up a full minute.
42-
// For example, if the movie length were 125 seconds:
43-
// 125 % 60 = 5, so there are 5 seconds left over after 2 full minutes.
44-
// Purpose: Extract the leftover seconds after converting total seconds into minutes.
39+
// It gives the remaining seconds that don’t make up a full minute.
4540

4641
// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
4742

4843
// const totalMinutes = (movieLength - remainingSeconds) / 60;
49-
// This line:
50-
// Subtracts the leftover seconds (that couldn’t form a full minute).
51-
52-
// Divides the remaining seconds by 60.
53-
// Meaning:
54-
// Converts the total movie length into minutes, ignoring any incomplete minute.
55-
// So it gives the total number of full minutes in the movie.
44+
// It subtracts the leftover seconds (that couldn’t form a full minute).
45+
// Then divides the remaining seconds by 60.
46+
// In doing so it converts the total movie length into minutes, ignoring any incomplete minute giving the total number of full minutes in the movie.
5647

5748
// e) What do you think the variable result represents? Can you think of a better name for this variable?
5849

5950
// const result = `${totalHours}:${remainingMinutes}:${remainingSeconds}`;
6051

6152
// This combines hours, minutes, and seconds into a single string formatted like H:M:S.
6253
// Example output: "2:26:24"
63-
// Meaning: It represents the formatted time duration of the movie.
54+
//
6455
// Better variable names:
65-
// formattedDuration
66-
// timeString
67-
// movieTime
68-
// durationInHMS
56+
// actualTime
57+
// timeAsUsual
58+
// timeExpected
6959

7060
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
7161

7262
// It will work correctly for most positive integers, since it’s just converting seconds into hours, minutes, and seconds using division and remainders.
7363
// However, there are some edge cases:
7464
// If movieLength = 0:
75-
// Output: 0:0:0 Works fine.
65+
// Output: 0:0:0 Works fine.
7666
// If movieLength < 60 (less than a minute):
7767
// Works fine (e.g., 45 → 0:0:45).
7868
// If movieLength is not an integer (e.g., 87.5):
7969
// Still works, but decimals might appear in remainingSeconds.
8070
// If movieLength is negative:
81-
// The logic breaks — you’d get negative time components ❌.
82-
// Formatting issue:
71+
// The time format breaks giving negative time components.
8372

73+
// Formatting issue:
8474
// The output isn’t padded.
8575
// Example: 2 hours, 5 minutes, 9 seconds → "2:5:9" instead of "02:05:09".
86-
// (Can fix that with .padStart(2, '0') on each component.)
87-
88-
// Summary:
89-
// It works for positive whole numbers, but for negative or non-integer inputs, or if you need formatted time, adjustments are needed.
90-
76+
// (Can fix that using function .padStart(2, '0') on each component.)
77+
//

0 commit comments

Comments
 (0)