Skip to content

Commit 69512a1

Browse files
author
Arthur
committed
Reply to the comment
1 parent e7bdeb9 commit 69512a1

2 files changed

Lines changed: 20 additions & 12 deletions

File tree

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ console.log(`The percentage change is ${percentageChange}`);
1414
// a) How many function calls are there in this file? Write down all the lines where a function call is made
1515
6
1616

17+
18+
carPrice = Number(carPrice.replaceAll(",", ""));
19+
priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));
20+
21+
console.log(`The percentage change is ${percentageChange}`);
22+
23+
1724
// 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?
1825
It lacks comma insides the replaceAll.
1926

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,33 @@
1-
const movieLength = 6; // length of movie in seconds
1+
const movieLength = 3540; // length of movie in seconds
22

33
const remainingSeconds = movieLength % 60;
44
const totalMinutes = (movieLength - remainingSeconds) / 60;
55

66
const remainingMinutes = totalMinutes % 60;
77
const totalHours = (totalMinutes - remainingMinutes) / 60;
88

9-
const result = `${totalHours}:${remainingMinutes}:${remainingSeconds}`;
10-
console.log(result);
9+
const formattedtime = `${totalHours}:${remainingMinutes}:${remainingSeconds}`;
10+
console.log(formattedtime);
1111

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-
//6
15+
6
1616
// b) How many function calls are there?
17-
//1
17+
1
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
2020

21-
//It divides totalMinutes into 60, see how much remainingMinutes left.
21+
It divides totalMinutes into 60, see how much remainingMinutes left.
2222

2323
// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
24-
//After deducting the totalMinutes, and divide the second. How much do he have the totalMinutes ?
24+
After deducting the totalMinutes, and divide the second. How much do he have the totalMinutes ?
2525

2626
// e) What do you think the variable result represents? Can you think of a better name for this variable?
27-
//The total duration of the movieLength.
27+
We can use formmattedtime to point out the time has been formatted.
2828

29-
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
30-
//for one hour = 3600 minutes . 1:00:00
31-
//for 59 minutes = 3540 minutes . 0:59:0
32-
//for seconds = 6 seconds . 0:0:6
29+
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
30+
for one hour = 3600 second . 1:00:00. No, it does not work here, because the remaining minutes and second forgets the extra zero.
31+
32+
//for 59 minutes = 3540 second . 0:59:0 No, it does not work here, because the remaining seconds and total hour forgets the extra zero.
33+
for seconds = 6 seconds . 0:0:6. No, it does not work here, because the totalHours, remainingMinutes and remaining seconds forgets the extra zero.

0 commit comments

Comments
 (0)