Skip to content

Commit 536761c

Browse files
committed
task 1-percentage-change explained
1 parent 08af9b8 commit 536761c

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

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

Lines changed: 6 additions & 3 deletions
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,11 +13,14 @@ 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-
// Answer: Line 4 'Number(), replaceAll()', line 5 'Number(), replaceAll()' and line 8, 100
16+
// Answer: Line 4 has 2 function call :'Number(), replaceAll()'.
17+
// Line 5 has 2 function call: 'Number(), replaceAll()'.
18+
// Line 10 has 1 function call console.log()
19+
// In total there are 5 function calls.
1720

1821
// 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?
1922
// Answer: The error is coming from line 5, spotting at the Number(priceAfterOneYear.replaceAll("," ""));
20-
// It's a synthax error missing a comma
23+
// It's a "SyntaxError: missing ) after argument list", missing a comma inside the replaceAll.() function.
2124

2225
// c) Identify all the lines that are variable reassignment statements
2326

0 commit comments

Comments
 (0)