Skip to content

Commit 85635a5

Browse files
committed
Solved mandatory-interpret/2-time-format.js
1 parent bbf4e20 commit 85635a5

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const movieLength = 8784; // length of movie in seconds
1+
const movieLength = 8468; // length of movie in seconds
22

33
const remainingSeconds = movieLength % 60;
44
const totalMinutes = (movieLength - remainingSeconds) / 60;
@@ -12,14 +12,25 @@ 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 6 variable declarations: movieLength, remainingSeconds, totalMinutes, remainingMinutes, totalHours, and result.
1516

1617
// b) How many function calls are there?
18+
// 1 function call: console.log(result);
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+
// This expression calculates the remainder or modulo when movieLength (in seconds) is divided by 60. This gives the number of seconds remaining after converting the total seconds into full minutes.
2023

2124
// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
25+
// It means the total number of full minutes in the movie length. It subtracts the remaining seconds from the total movie length and then divides that value by 60 to convert it from seconds to minutes.
2226

2327
// e) What do you think the variable result represents? Can you think of a better name for this variable?
28+
// It represents the formatted string of the movie length in hours, minutes and seconds. A better name could be formattedMovieTime or durationMovieFormatted.
2429

2530
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
31+
//Code works correctly, but there are few edge cases to consider:
32+
// 1. If movieLength is negative, the output won't make sense in the context of time duration.
33+
// 2. If movieLength is a very large number the output'll still be correct, but not readable - "1.7968563299644136e+35:4:52"
34+
// 3. If movieLength is zero, the output will be "0:0:0", which is valid but may not be the desired format for representing zero duration.
35+
// 4. If movieLength is not an integer like floating-point number, the calculations may yield unexpected results - "2:21:8.299999999999272" since time is typically represented in whole seconds.
36+
// 5. When hours, minutes or seconds are single digits (1:5:3) the output may not be in the desired format with 2digits - "01:05:03".

0 commit comments

Comments
 (0)