Skip to content

Commit 28d1d37

Browse files
committed
Complete time format interpretation
1 parent 6a10112 commit 28d1d37

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

‎Sprint-2/3-mandatory-interpret/2-time-format.js‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,26 @@ console.log(result);
1212
// For the piece of code above, read the code and then answer the following questions
1313

1414
// 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.)
1517

1618
// b) How many function calls are there?
19+
// There is 1 function call: console.log(result)
1720

1821
// 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.
1924
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
2025

2126
// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
27+
// totalMinutes = (movieLength - remainingSeconds) / 60
28+
// 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.
2230

2331
// 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.
2434

2535
// 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

Comments
 (0)