Skip to content

Commit 13c32aa

Browse files
committed
Fix syntax error in priceAfterOneYear assignment and enhance comments for clarity
1 parent d8109f2 commit 13c32aa

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,24 @@ 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-
// Read the code and then answer the questions below
13-
1412
// a) How many function calls are there in this file? Write down all the lines where a function call is made
13+
// There are five function calls: carPrice.replaceAll(",", ""), Number(carPrice.replaceAll(",", "")), priceAfterOneYear.replaceAll(",", ""), Number(priceAfterOneYear.replaceAll(",", "")), and console.log(...).
1514

1615
// 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?
16+
// The error comes from the line priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); because there is a missing comma between the arguments in replaceAll, which causes a syntax error. It can be fixed by writing replaceAll(",", "") instead.
1717

1818
// c) Identify all the lines that are variable reassignment statements
19+
// The variable reassignment statements are carPrice = Number(carPrice.replaceAll(",", "")); and priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));.
1920

2021
// d) Identify all the lines that are variable declarations
22+
// The variable declarations are let carPrice = "10,000";, let priceAfterOneYear = "8,543";, const priceDifference = carPrice - priceAfterOneYear;, and const percentageChange = (priceDifference / carPrice) * 100;.
2123

22-
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
24+
// e) Describe what the expression Number(carPrice.replaceAll(",", "")) is doing - what is the purpose of this expression?
25+
// The expression first removes the comma from the string "10,000" using replaceAll(",", ""), resulting in "10000", and then converts that string into a number using Number(), so that it can be used in mathematical calculations.

0 commit comments

Comments
 (0)