Skip to content

Commit 7459cb4

Browse files
committed
fix: Calculate percentage change between initial and final car prices
1 parent e781b95 commit 7459cb4

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,30 @@ console.log(`The percentage change is ${percentageChange}`);
1212
// Read the code and then answer the questions below
1313

1414
// a) How many function calls are there in this file? Write down all the lines where a function call is made
15+
// There are 5 function calls in this file. The lines where a function call is made are:
16+
// Line 1: carPrice.replaceAll(",", "")
17+
// Line 2: priceAfterOneYear.replaceAll(",", "")
18+
// Line 3: Number(carPrice.replaceAll(",", ""))
19+
// Line 4: Number(priceAfterOneYear.replaceAll(",", ""))
20+
// Line 5: console.log(`The percentage change is ${percentageChange}`)
1521

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?
23+
// The error is occurring in line 5, because it's missing a comma between the two arguments of the replaceAll method.
24+
// to fix this problem, we can add a comma between the two arguments: priceAfterOneYear.replaceAll(",", "")
1725

1826
// c) Identify all the lines that are variable reassignment statements
27+
// there are 2 variable reassignment statements in this file. The lines where a variable reassignment is made are:
28+
// Line 4 and 5 where we are reassigning new values to the variables
29+
// carPrice and priceAfterOneYear after converting them to numbers and removing the commas.
1930

2031
// d) Identify all the lines that are variable declarations
32+
// there are 4 variable declarations in this file. The lines where a variable declaration is made are:
33+
// Line 1: let carPrice = "10,000";
34+
// Line 2: let priceAfterOneYear = "8,543";
35+
// Line 6: const priceDifference = carPrice - priceAfterOneYear;
36+
// Line 7: const percentageChange = (priceDifference / carPrice) * 100;
2137

2238
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
39+
// To remove the commas from the string carPrice and convert the resulting string to a number.
40+
// Then, the Number function is used to convert the resulting string into a number data type,
41+
// which can be used for mathematical operations.

0 commit comments

Comments
 (0)