Skip to content

Commit 596785a

Browse files
committed
2-time-format.js
1 parent ef37add commit 596785a

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,33 @@ 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 variable declarations
16+
//Line 1: movieLength
17+
//Line 3: remainingSeconds
18+
//Line 4: totalMinutes
19+
//Line 6: remainingMinutes
20+
//Line 7: totalHours
21+
//Line 9: result
1522

1623
// b) How many function calls are there?
24+
// 1 function call
25+
//Line 10: console.log(result)
1726

1827
// c) Using documentation, explain what the expression movieLength % 60 represents
1928
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
29+
// The % operator is the remainder operator. It returns the remainder left over when one operand is divided by a second operand.
30+
// In this case, movieLength % 60 calculates the number of seconds remaining after dividing the total movie length by 60 (the number of seconds in a minute).
31+
// For example, if movieLength is 8784 seconds, then 8784 % 60 equals 24, meaning there are 24 seconds left over after accounting for full minutes.
2032

2133
// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
34+
// The expression (movieLength - remainingSeconds) / 60 calculates the total number of minutes in the movie by first removing the remaining seconds and then dividing by 60 (the number of seconds in a minute).
2235

2336
// e) What do you think the variable result represents? Can you think of a better name for this variable?
37+
// The variable result represents the formatted string output of the total hours, remaining minutes, and remaining seconds of the movie.
38+
// A better name for this variable could be formattedMovieLength.
2439

2540
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
41+
// The code will work for all non-negative integer values of movieLength. It correctly calculates hours, minutes, and seconds for any length of time.
42+
// However, if movieLength is negative or not an integer, the results may not make sense in the context of a movie length.
43+
// For example, if movieLength is negative, the calculations for hours, minutes, and seconds will yield negative values, which are not valid for a movie duration.
44+
// Additionally, if movieLength is a non-integer (e.g., a float), the calculations will still work, but the interpretation of the result may be less clear since movie lengths are typically represented as whole seconds.

0 commit comments

Comments
 (0)