Skip to content

Commit fea47a8

Browse files
committed
2-time-format.js
1 parent 49bec3d commit fea47a8

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

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

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,48 @@ console.log(result);
2323
// e) What do you think the variable result represents? Can you think of a better name for this variable?
2424

2525
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
26+
27+
28+
/* SOLUTION
29+
30+
a) **How many variable declarations are there in this program?**
31+
There are **5** variable declarations: `movieLength`, `remainingSeconds`, `totalMinutes`, `remainingMinutes`, `totalHours`, and `result`.
32+
33+
b) **How many function calls are there?**
34+
- The template literal uses `${...}` expressions, but these are not function calls.
35+
- The only function call is `console.log(result);`.
36+
So, there is **1** function call.
37+
38+
c) **Using documentation, explain what the expression `movieLength % 60` represents**
39+
The `%` operator returns the remainder after dividing `movieLength` by `60`. In this context, it gives the number of seconds left after converting as many full minutes
40+
as possible from the total seconds.
41+
42+
d) **Interpret line 4, what does the expression assigned to `totalMinutes` mean?**
43+
`(movieLength - remainingSeconds) / 60` subtracts the leftover seconds from the total, then divides by 60 to get the total number of complete minutes in the movie.
44+
45+
e) **What do you think the variable `result` represents? Can you think of a better name for this variable?**
46+
`result` represents the movie length formatted as `hours:minutes:seconds`. A better name could be `formattedTime` or `movieLengthHMS`.
47+
48+
f) **Try experimenting with different values of `movieLength`. Will this code work for all values of `movieLength`? Explain your answer**
49+
The code works for positive integer values of `movieLength`. However, for values less than 60, `totalHours` and `remainingMinutes` will be `0`, which is correct.
50+
For negative or non-integer values, the output may not make sense. Also, the output does not pad single-digit minutes or seconds with a leading zero (e.g., `1:2:3` instead of `01:02:03`).
51+
52+
53+
54+
55+
56+
57+
58+
59+
60+
61+
62+
63+
64+
65+
66+
67+
68+
69+
70+
*/

0 commit comments

Comments
 (0)