Skip to content

Commit d008b71

Browse files
answer 3.1
1 parent 83dd7a0 commit d008b71

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,18 @@ const percentageChange = (priceDifference / carPrice) * 100;
99

1010
console.log(`The percentage change is ${percentageChange}`);
1111

12-
// Read the code and then answer the questions below
12+
The error is on this line:
1313

14-
// a) How many function calls are there in this file? Write down all the lines where a function call is made
14+
There is a missing comma between "," and "".
1515

16-
// 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?
16+
priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));
1717

18-
// c) Identify all the lines that are variable reassignment statements
18+
Final corrected code is going to be:
1919

20-
// d) Identify all the lines that are variable declarations
21-
22-
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
20+
let carPrice = "10,000";
21+
let priceAfterOneYear = "8,543";
22+
carPrice = Number(carPrice.replaceAll(",", ""));
23+
priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));
24+
const priceDifference = carPrice - priceAfterOneYear;
25+
const percentageChange = (priceDifference / carPrice) * 100;
26+
console.log(`The percentage change is ${percentageChange}`);

0 commit comments

Comments
 (0)