Skip to content

Commit cb505df

Browse files
committed
Answer to 3-mandatory-interpret/2-time-format.js explanation/answers included as text
1 parent 4004b30 commit cb505df

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

Sprint-1/3-mandatory-interpret/1-percentage-change.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ console.log(`The percentage change is ${percentageChange}`);
1919
// There are 3 function calls in this file. They are on lines 4, 5, and 10. The function calls are: two uses of replaceAll,and one console.log.
2020
// b) Run the code and identify the line where the error is coming from - why is this error occurring? How can you fix this problem?
2121
// The error is coming from lines 4 and 5 (which I have commed out). The error is occurring because there is a space between the comma and the closing quotation mark in the second argument of the replaceAll function. This causes the function to look for a comma followed by a space, which does not exist in the string. To fix this problem, have removed the space between the comma and the closing quotation mark in both lines, on lines 7&8.
22-
2322
// c) Identify all the lines that are variable reassignment statements
2423
// The variable reassignment statements are on lines 7 and 8, where carPrice and priceAfterOneYear are being reassigned to the result of the replaceAll function calls.
2524

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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-
15+
// There are 6 variable declarations in this program. They are: movieLength, remainingSeconds, totalMinutes, remainingMinutes, totalHours, and result.
1616
// b) How many function calls are there?
17+
// There are 2 function calls in this program. They are: the template literal function call when assigning a value to the result variable (line 9) and the console.log function call on line 10.
1718

1819
// c) Using documentation, explain what the expression movieLength % 60 represents
1920
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
21+
// The expression movieLength % 60 calculates the remainder when movieLength is divided by 60. This gives us the number of seconds that are left over after converting the total seconds into minutes. Movilength is 146 minutes and 24 seconds, so the remaining seconds is 24.
2022

2123
// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
24+
// The expression (movieLength - remainingSeconds) / 60 calculates the total number of minutes in the movie, excluding the remaining seconds, based on the movilength (8784s)so the calculation is; (8784-24)/60 = 146 minutes.
25+
2226

2327
// e) What do you think the variable result represents? Can you think of a better name for this variable?
2428

29+
// The variable result is the length of the movie in hours, minutes, and seconds. A better name for this variable could be movieDurationhms, as it more clearly indicates that it is the duration of the movie in hours, minutes, and seconds.
30+
2531
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
32+
// Movie length will work for all integers, based it it being a real movie and therefore non negative and the timing device only able to measure whole seconds. If movieLength is not an integer (e.g., a floating-point number), the calculations may yield unexpected results due to the way JavaScript handles division and modulus operations with non-integer values.

0 commit comments

Comments
 (0)