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
// 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. movieLength
17
+
// 2. remainingSeconds
18
+
// 3. totalMinutes
19
+
// 4. remainingMinutes
20
+
// 5. totalHours
21
+
// 6. result
15
22
16
23
// b) How many function calls are there?
24
+
// their is 1 function call
25
+
// console.log(result);
17
26
18
-
// c) Using documentation, explain what the expression movieLength % 60 represents
27
+
// c) Using documentation, explain what the expression movieLength % 60 represents The is expressing remaining number of seconds after converted to 60 seconds
28
+
// The expression `movieLength % 60` calculates the remainder when `movieLength` (the length of the movie in seconds)
29
+
// This gives the number of seconds that do not complete a full minute, effectively representing the remaining seconds after converting the total movie length into minutes.
// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
22
-
33
+
// The expression (movieLength - remainingSeconds) / 60 determines the total number of full minutes in the movie by removing the leftover seconds and then dividing the result by 60.
23
34
// e) What do you think the variable result represents? Can you think of a better name for this variable?
24
-
35
+
//time
36
+
// The variable `result` represents the formatted time of the movie in the format "hours:minutes:seconds".
37
+
// A better name for this variable could be "movieDuration" to make it clearer that it holds the duration of the movie in a specific format.
25
38
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
0 commit comments