Skip to content

Commit a5e6cba

Browse files
Fix percentage change exercise
1 parent 923135a commit a5e6cba

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

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

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

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

77
const priceDifference = carPrice - priceAfterOneYear;
88
const percentageChange = (priceDifference / carPrice) * 100;
@@ -13,10 +13,33 @@ 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+
// 5 function calls
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+
// Error: SyntaxError: missing ) after argument list
24+
// The error comes from:
25+
// priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));
26+
// Why: The comma between the two arguments of replaceAll() is missing.
27+
// Fix: Add the missing comma:
28+
// priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));
29+
30+
1831
// c) Identify all the lines that are variable reassignment statements
1932

33+
// carPrice = Number(carPrice.replaceAll(",", ""));
34+
// priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));
35+
2036
// d) Identify all the lines that are variable declarations
2137

38+
// let carPrice = "10,000";
39+
// let priceAfterOneYear = "8,543";
40+
// const priceDifference = carPrice - priceAfterOneYear;
41+
// const percentageChange = (priceDifference / carPrice) * 100;
42+
2243
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
44+
45+
// It removes the comma from the string and converts the resulting string into a number.

0 commit comments

Comments
 (0)