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
@@ -23,3 +23,31 @@ console.log(result);
23
23
// e) What do you think the variable result represents? Can you think of a better name for this variable?
24
24
25
25
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
26
+
27
+
/*
28
+
Answer
29
+
a)In this program there are 5 variable declarations:
30
+
-const movieLength = 8784; at line 1.
31
+
-const remainingSeconds = movieLength % 60; at line 3.
32
+
-const totalMinutes = (movieLength - remainingSeconds) / 60; at line 4.
33
+
-const remainingMinutes = totalMinutes % 60; at line 6.
34
+
-const totalHours = (totalMinutes - remainingMinutes) / 60; at line 7.
35
+
36
+
b) There are only 1 function call in this program.
37
+
- console.log(result); at line 10
38
+
39
+
c)At the line 3 we can see the the expression movieLength % 60,
40
+
what is represent is the reminder value after the division movieLength(in second) value by 60%;
41
+
this is to remind how much left over second left in the movie.
42
+
43
+
d)In line 4, the the expression that is assigned to totalMinutes
44
+
represent the value after the math operation if movieLength value and remainingSeconds then divine by 60;
45
+
46
+
e)For the variable result it represent the combine total time length of the movie in hour/minutes/second template, for better name for this variable
47
+
I would to rename it to totalMovieLength.
48
+
49
+
f) After the experimenting with different values of movieLength. As Long as the value in movieLength is a positive integer of second. It will
50
+
correctly produce the correct value in hours/minutes/second format. However for to the other value such as float number, string, negative integer
51
+
and non numeric value. They might still print out in the format hours/minutes/second but some type will break code such as if string not a number or coma in a string
52
+
number, negative value that don't reflect what this code try to do or decimal number that give incorrect result.
0 commit comments