Skip to content

Commit 8ca06db

Browse files
committed
Complete percentage change interpretation
1 parent 43b8618 commit 8ca06db

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@ 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;
99

1010
console.log(`The percentage change is ${percentageChange}`);
11-
1211
// Read the code and then answer the questions below
1312

1413
// a) How many function calls are there in this file? Write down all the lines where a function call is made
@@ -19,4 +18,19 @@ console.log(`The percentage change is ${percentageChange}`);
1918

2019
// d) Identify all the lines that are variable declarations
2120

22-
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
21+
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of thi e() and Number().
22+
23+
//a) There are 4 function calls. They are on lines 4 and 5. Each line contains two function calls: replaceAll() and Number().
24+
//b) The error comes from line 5. The replaceAll() function is missing a comma between its two arguments. The problem can be fixed by adding a comma: replaceAll(",", "").
25+
//priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));
26+
//c) The variable reassignment statements are lines 4 and 5.
27+
//d) The variable declaration statements are lines 1, 2, 7 and 8.
28+
29+
//e) The expression removes the comma from the price string and then converts the result from a string into a number, so JavaScript can use it for calculations.
30+
31+
//carPrice = Number(carPrice.replaceAll(",", ""));
32+
//priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));
33+
34+
//const priceDifference = carPrice - priceAfterOneYear;
35+
//const percentageChange = (priceDifference / carPrice) * 100;
36+

0 commit comments

Comments
 (0)