Skip to content

Commit 03cb451

Browse files
committed
Explain variables, function calls, expressions, and result interpretation in code
1 parent 3090d19 commit 03cb451

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

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

Lines changed: 8 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 = 8974; // length of movie in seconds
22

33
const remainingSeconds = movieLength % 60;
44
const totalMinutes = (movieLength - remainingSeconds) / 60;
@@ -12,14 +12,21 @@ 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+
//Answer: There are six variable declarations in this program
1516

1617
// b) How many function calls are there?
18+
// Answer: There is only one function call in the program
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+
// Answer: The expression movieLength % 60 represents the remainder when movieLength is divided by 60
2023

2124
// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
25+
// Answer: The expression assigned to totalMinutes subtracts the leftover seconds from the movieLength and divide it by 60 to get the totalMinutes.
26+
// This gives the total whole minutes of the movie without the leftover seconds.
2227

2328
// e) What do you think the variable result represents? Can you think of a better name for this variable?
29+
// Answer: The variable result represents the time in hours, minutes and seconds. A better name for the variable could be totalTime
2430

2531
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
32+
// Answer: I tried different positive values of movieLength and the code worked for all but result variable returned a negative value when I tried a negative number as the variable movieLength

0 commit comments

Comments
 (0)