Skip to content

Commit db7d71e

Browse files
committed
answered all questions
1 parent 1d240a1 commit db7d71e

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,24 @@ 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+
// 6 -> movieLength, remainingSeconds, totalMinutes, remainingMinutes, totalHours, result
1516

1617
// b) How many function calls are there?
18+
// -> console.log() on the last line
1719

1820
// c) Using documentation, explain what the expression movieLength % 60 represents
1921
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
22+
// % is the modulo (remainder) operator. movieLength % 60 gives the leftover seconds
23+
// after dividing by 60. e.g. 8784 / 60 = 146 remainder 24, so remainingSeconds = 24
2024

2125
// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
26+
// movieLength - remainingSeconds gives the total number of seconds that can be divided into whole minutes.
27+
// Dividing this by 60 gives the total number of whole minutes in the movie. e.g. 8784 - 24 = 8760, 8760 / 60 = 146
2228

2329
// e) What do you think the variable result represents? Can you think of a better name for this variable?
30+
// result represents the movie length formatted as hours:minutes:seconds e.g. "2:26:24"
31+
// A better name could be formattedMovieLength or totalFormattedMovieLength
2432

2533
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
34+
// It works for any positive whole number of seconds.
35+
// It won't work correctly for negative values or decimals as % behaves unexpectedly with those.

0 commit comments

Comments
 (0)