You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Sprint-1/3-mandatory-interpret/2-time-format.js
+38Lines changed: 38 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -12,14 +12,52 @@ console.log(result);
12
12
// For the piece of code above, read the code and then answer the following questions
13
13
14
14
// a) How many variable declarations are there in this program?
15
+
/* There are 6 variable declarations:
16
+
1.Line 1 : const movieLength.
17
+
2.Line 3 : const remainingSeconds.
18
+
3.Line 4 : const totalMinutes.
19
+
4.Line 6 : const remainingMinutes.
20
+
5.Line 7 : const totalHours.
21
+
6.Line 9 : const result.
22
+
*/
15
23
16
24
// b) How many function calls are there?
17
25
26
+
/* There is one function call:
27
+
Line 10 : console.log().
28
+
*/
29
+
18
30
// c) Using documentation, explain what the expression movieLength % 60 represents
31
+
32
+
/* The movieLength represents the length of the movie in seconds, the operand % is remaining (Modulo) returns the remaining of the movieLength divided by 60(to convert sec into minutes) but it only gives the remaining of this operation.
// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
22
38
39
+
/*
40
+
The expression assigned to completed total minutes of the movie, by subtract the movie length in sec from the remaining seconds and divide the result by 60 to convert it to minutes
41
+
*/
42
+
23
43
// e) What do you think the variable result represents? Can you think of a better name for this variable?
24
44
45
+
/*
46
+
The variable result display the total length of the movie in these form (Hours:Minutes:seconds) in string format.
47
+
48
+
I can think of "MovieDuration" as a better name because it gives more description to the output.
49
+
*/
50
+
25
51
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
52
+
53
+
/*
54
+
I did experimenting the code by putting different value to the movieLength and it works just fine.
55
+
56
+
test numbers and its outcomes:
57
+
1. 36000sec>> 10:0:0
58
+
2. 120 sec >> 0:2:0
59
+
3. 0 sec >> 0:0:0
60
+
4. 555555.55sec >> 154:19:15.550000000046566
61
+
62
+
As the results show the code is working fine even with unexpected large numbers.
0 commit comments