Skip to content

Commit 22aca43

Browse files
committed
Update 2-time-format.js
Answered questions
1 parent 978fdbf commit 22aca43

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,41 @@ console.log(result);
1313

1414
// a) How many variable declarations are there in this program?
1515

16+
// There are 6 variable declarations in this program. They are on lines 1, 3, 5, 7, 9 and 11. The variables being declared are movieLength, remainingSeconds, totalMinutes, remainingMinutes, totalHours and result.
17+
18+
19+
1620
// b) How many function calls are there?
1721

22+
// There is 1 function calls in this program. It is on lines 10. The functions is the console.log().
23+
24+
25+
1826
// c) Using documentation, explain what the expression movieLength % 60 represents
1927
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
2028

29+
// % is the remainder operator.
30+
// movieLength % 60 - This gives the remainder when movieLength is divided by 60.
31+
// Since there are 60 seconds in a minute, this tells us how many leftover seconds there are after counting full minutes.
32+
// For example, 8784 % 60 = 24. So there are 24 seconds left after counting the minutes.
33+
34+
35+
2136
// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
2237

38+
// movieLength - remainingSecond - This gives the total number of seconds in the movie after removing the leftover seconds.
39+
// Divide by 60 - this converst the seconds into total full minutes. eg. (8784 - 24) = 8760, 8760 / 60 = 146.
40+
41+
42+
2343
// e) What do you think the variable result represents? Can you think of a better name for this variable?
2444

45+
// The variable result is a string that represents the movie length in hours:minutes:seconds
46+
// For example: 2:26:24 (2 hours, 26 minutes, 24 seconds)
47+
// Better name can be movieDurationString.
48+
49+
50+
2551
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
52+
53+
// This code will work for all positive integer values of movieLength. It will correctly calculate the hours, minutes and seconds for any length of movie. However, if movieLength is negative or not an integer, the code may not work as intended. For example, if movieLength is -100, the calculations will not make sense in the context of a movie length. If movieLength is a decimal, it may also cause issues with the calculations.

0 commit comments

Comments
 (0)