Skip to content

Commit 08355c3

Browse files
committed
answering interpret 1 and fixed its error
1 parent fe4a1a4 commit 08355c3

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

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

Lines changed: 17 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,26 @@ 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 4 function calls in this file
17+
// Line 4: carPrice.replaceAll(",", "")
18+
// Line 4: Number(carPrice.replaceAll(",", ""))
19+
// Line 5: priceAfterOneYear.replaceAll("," "")
20+
// Line 5: Number(priceAfterOneYear.replaceAll("," ""))
21+
1622
// 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?
1723

24+
// The error is coming from line 5
25+
// The error is due to a missing comma
26+
// Add a comma between the two quotations
27+
1828
// c) Identify all the lines that are variable reassignment statements
1929

30+
// Line 4 and Line 5
31+
2032
// d) Identify all the lines that are variable declarations
2133

34+
// Line 1, Line 2, Line 7 and Line 8
35+
2236
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
37+
38+
// The expression is replacing all the commas in the string carPrice with nothing, and then converting it to a number type

0 commit comments

Comments
 (0)