Skip to content

Commit 24f5004

Browse files
authored
Modify movieLength and enhance comments for clarity
Updated movieLength to a negative value and added comments for clarity on variable declarations and function calls. Suggested improvements for handling negative movie lengths.
1 parent d35032e commit 24f5004

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const movieLength = 8784; // length of movie in seconds
2-
1+
const movieLength = -1000000; // length of movie in seconds
2+
//not complete
33
const remainingSeconds = movieLength % 60;
44
const totalMinutes = (movieLength - remainingSeconds) / 60;
55

@@ -11,17 +11,21 @@ console.log(result);
1111

1212
// For the piece of code above, read the code and then answer the following questions
1313

14-
// a) How many variable declarations are there in this program?
14+
// a) How many variable declarations are there in this program?
1515
// 6 declarations
1616
// b) How many function calls are there?
1717
// 1 function call in line 10
1818
// c) Using documentation, explain what the expression movieLength % 60 represents
1919
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
20-
// "operator returns the remainder left over when one operand is divided by a second operand. It always takes the sign of the dividend."
20+
// it represent the number of seconds left over after taking all the complete minutes
21+
2122
// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
22-
// it means the number of minutes in a film is calculated by calculating the number of seconds in the film
23+
//here in the expression we have the movieLength taken from it the number of remainingSeconds, so the operator / 60 represents the conversion of the remaining seconds into minuttes, so we left with complete minutes only
2324
// e) What do you think the variable result represents? Can you think of a better name for this variable?
2425
//the variable result represesnt the length of the film in hours,minutes,and seconds. A better name would be movie time.
2526
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
26-
// However, it doesn't work when the leading number of a decimal is zero like this 08784 because it interpreted as octal literal and 8 can't work in octal numeration
27-
//"The octal number system is a base-8 math and computing system that uses only eight digits: 0, 1, 2, 3, 4, 5, 6, and 7"
27+
//8784
28+
//if experimented values into the movieLength variable what will happen? Lets start with the following values:
29+
//-10 , 0, 10 , 10000000, -1000000
30+
//0:0:-10, 0:0:0,0:0:10,2777:46:40, -277:-46:-40
31+
//ok I notice the result get strange with big negative numbers, so I think the code needs to be modified to restrict using negative values

0 commit comments

Comments
 (0)