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-2/3-mandatory-interpret/2-time-format.js
+12Lines changed: 12 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -12,14 +12,26 @@ 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 7 variable declarations: movieLength, remainingSeconds, totalMinutes, remainingMinutes, totalHours, result, and maybe the console.log has none.
16
+
// (If counting only const declarations, there are 6: movieLength, remainingSeconds, totalMinutes, remainingMinutes, totalHours, result.)
15
17
16
18
// b) How many function calls are there?
19
+
// There is 1 function call: console.log(result)
17
20
18
21
// c) Using documentation, explain what the expression movieLength % 60 represents
22
+
// % is the remainder operator. It gives the remainder when movieLength is divided by 60.
23
+
// For 8784 seconds, 8784 % 60 = 24, so there are 24 seconds remaining after full minutes are counted.
// This removes the extra seconds left over after full minutes are taken out, then divides by 60 to convert the remaining whole seconds into total minutes.
29
+
// For 8784 seconds, this gives 146 minutes.
22
30
23
31
// e) What do you think the variable result represents? Can you think of a better name for this variable?
32
+
// result represents the time formatted as hours:minutes:seconds.
33
+
// A better name could be timeString or formattedTime.
24
34
25
35
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
36
+
// It works for any non-negative number of seconds, because it calculates hours, minutes, and seconds using division and remainders.
37
+
// It will not format correctly for negative values, and it assumes the value is in seconds rather than another unit.
0 commit comments