Skip to content

Commit e4e308f

Browse files
committed
done time-format.js
1 parent 7ed2bbc commit e4e308f

File tree

1 file changed

+42
-8
lines changed

1 file changed

+42
-8
lines changed

Sprint-1/interpret/time-format.js

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,58 @@
1-
const movieLength = 8784; // length of movie in seconds
1+
const movieLength = 8784; // length of movie in seconds 8784
22

33
const remainingSeconds = movieLength % 60;
4+
console.log(remainingSeconds);
5+
46
const totalMinutes = (movieLength - remainingSeconds) / 60;
7+
console.log(totalMinutes);
58

69
const remainingMinutes = totalMinutes % 60;
10+
console.log(remainingMinutes);
11+
12+
713
const totalHours = (totalMinutes - remainingMinutes) / 60;
814

915
const result = `${totalHours}:${remainingMinutes}:${remainingSeconds}`;
1016
console.log(result);
1117

12-
// For the piece of code above, read the code and then answer the following questions
18+
/*
19+
For the piece of code above, read the code and then answer the following questions
20+
21+
a) How many variable declarations are there in this program?
22+
23+
-------- 6 in total
24+
-------- movieLength - declared as const
25+
-------- remainingSeconds - declared as const
26+
-------- totalMinutes - declared as const
27+
-------- remainingMinutes - declared as const
28+
-------- totalHours - declared as const
29+
-------- result - declared as const
30+
31+
32+
b) How many function calls are there?
33+
34+
-------- console.log(result);
35+
36+
c) Using documentation, explain what the expression movieLength % 60 represents
37+
38+
-------- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Remainder
39+
-------- Remainder:
40+
-------- WITH % we can obtain the remainder between the var movieLength % 60; and stored in remainingMinutes
1341
14-
// a) How many variable declarations are there in this program?
42+
d) Interpret line 4, what does the expression assigned to totalMinutes mean?
1543
16-
// b) How many function calls are there?
44+
-------- This line is taking the leftover remainder in remainingMinutes and leaving just the
45+
total amount that we can divide perfectly in whole number to see how many minutes we have.
1746
18-
// c) Using documentation, explain what the expression movieLength % 60 represents
47+
e) What do you think the variable result represents? Can you think of a better name for this variable?
1948
20-
// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
49+
------- Result var represent the total runtime of the movie, the nameVar is fine but we can name it as
50+
timeMovie for better readability, as it gives future readers a better idea of the variable's purpose.
2151
22-
// e) What do you think the variable result represents? Can you think of a better name for this variable?
52+
f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
2353
24-
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
54+
------- This code works as expected for the most of positive values of movieLength. Just
55+
when I write negative number in the result will show the negative sign. eg.
56+
const movieLength = -4258;
57+
result: -1:-10:-58
58+
*/

0 commit comments

Comments
 (0)