Skip to content

Commit b1ecc00

Browse files
Fix typo in priceAfterOneYear conversion and update comments for clarity
1 parent 1743941 commit b1ecc00

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,36 @@ 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}`);
1111

12+
1213
// Read the code and then answer the questions below
1314

1415
// a) How many function calls are there in this file? Write down all the lines where a function call is made
16+
// there are 5 function calls :
17+
// carPrice = Number(carPrice.replaceAll(",", ""));
18+
// priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));
19+
// console.log(`The percentage change is ${percentageChange}`);
20+
21+
1522

1623
// 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?
24+
//the error appears on line 5 because of a missing coma between the arguments, fixed by adding a coma
1725

1826
// c) Identify all the lines that are variable reassignment statements
27+
// carPrice = Number(carPrice.replaceAll(",", ""));
28+
// priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));
1929

2030
// d) Identify all the lines that are variable declarations
31+
// let carPrice = "10,000";
32+
// let priceAfterOneYear = "8,543";
33+
// const priceDifference = carPrice - priceAfterOneYear;
34+
// const percentageChange = (priceDifference / carPrice) * 100;
2135

2236
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
37+
//it get's rid of the coma and turns the string in to a number

0 commit comments

Comments
 (0)