Skip to content

Commit 18135db

Browse files
committed
I understand now why we use replcaeAll
1 parent a400f92 commit 18135db

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

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

Lines changed: 11 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,20 @@ 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+
// functions calls are on lines 4,5,8 and 10.
17+
1618
// 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?
1719

20+
// the line where the error is coming from is line 5, because there wasn't a comma between argument in replaceAll(",", "")).
21+
1822
// c) Identify all the lines that are variable reassignment statements
1923

24+
// the lines that variable reassignment are 4 and 5.
25+
2026
// d) Identify all the lines that are variable declarations
2127

28+
// the lines where variable declarations are 1 and 2
29+
2230
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
31+
32+
// we have carPrice which is a STRING AND ALSO 10,000 so need to replaceAll and remove the commas to turn it into a number so we can do math

0 commit comments

Comments
 (0)