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
+28Lines changed: 28 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -13,13 +13,41 @@ console.log(result);
13
13
14
14
// a) How many variable declarations are there in this program?
15
15
16
+
// There are 6 variable declarations in this program. They are on lines 1, 3, 5, 7, 9 and 11. The variables being declared are movieLength, remainingSeconds, totalMinutes, remainingMinutes, totalHours and result.
17
+
18
+
19
+
16
20
// b) How many function calls are there?
17
21
22
+
// There is 1 function calls in this program. It is on lines 10. The functions is the console.log().
23
+
24
+
25
+
18
26
// c) Using documentation, explain what the expression movieLength % 60 represents
// movieLength % 60 - This gives the remainder when movieLength is divided by 60.
31
+
// Since there are 60 seconds in a minute, this tells us how many leftover seconds there are after counting full minutes.
32
+
// For example, 8784 % 60 = 24. So there are 24 seconds left after counting the minutes.
33
+
34
+
35
+
21
36
// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
22
37
38
+
// movieLength - remainingSecond - This gives the total number of seconds in the movie after removing the leftover seconds.
39
+
// Divide by 60 - this converst the seconds into total full minutes. eg. (8784 - 24) = 8760, 8760 / 60 = 146.
40
+
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
+
// The variable result is a string that represents the movie length in hours:minutes:seconds
46
+
// For example: 2:26:24 (2 hours, 26 minutes, 24 seconds)
47
+
// Better name can be movieDurationString.
48
+
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
+
// This code will work for all positive integer values of movieLength. It will correctly calculate the hours, minutes and seconds for any length of movie. However, if movieLength is negative or not an integer, the code may not work as intended. For example, if movieLength is -100, the calculations will not make sense in the context of a movie length. If movieLength is a decimal, it may also cause issues with the calculations.
0 commit comments