Skip to content

Commit fca8c46

Browse files
authored
Fix syntax error and added comments to answer the questions.
Fixed syntax error by adding a missing comma in replaceAll function calls.
1 parent eaf8513 commit fca8c46

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
let carPrice = "10,000";
22
let priceAfterOneYear = "8,543";
33

4-
carPrice = Number(carPrice.replaceAll(",", ""));
5-
priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));
4+
carPrice = Number(carPrice.replaceAll(",",""));
5+
priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",",""));
66

77
const priceDifference = carPrice - priceAfterOneYear;
88
const percentageChange = (priceDifference / carPrice) * 100;
@@ -13,10 +13,27 @@ console.log(`The percentage change is ${percentageChange}`);
1313

1414
// a) How many function calls are there in this file? Write down all the lines where a function call is made
1515

16+
//There are three function calls: replaceAll() - used twice, number() - used twice, console.log() - used once.
17+
// carPrice = Number(carPrice.replaceAll("," , ""));
18+
// priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," , ""));
19+
// console.log(`The percentage change is ${percentageChange}`);
20+
1621
// 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?
1722

23+
//There was a syntax error on line five, missing comma. Fixed by adding one.
24+
1825
// c) Identify all the lines that are variable reassignment statements
1926

27+
//carPrice = Number(carPrice.replaceAll("," , ""));
28+
//priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," , ""));
29+
2030
// d) Identify all the lines that are variable declarations
2131

32+
//let carPrice = "10,000";
33+
//let priceAfterOneYear = "8,543";
34+
//const priceDifference = carPrice - priceAfterOneYear;
35+
//const percentageChange = (priceDifference / carPrice) * 100;
36+
2237
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
38+
39+
// It's removing the commas, since javascript will recognise 10,000 as a string not a number.

0 commit comments

Comments
 (0)