Skip to content

Commit b06aae3

Browse files
committed
Add comments to clarify function calls, variable assignments, and error identification in percentage change calculation
1 parent 1c5023d commit b06aae3

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,26 @@ 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+
//1. Line 5: carPrice.replaceAll(",", "")
16+
//2. Line 6: priceAfterOneYear.replaceAll(",", "")
17+
//3. Line 8: console.log(`The percentage change is ${percentageChange}`)
1518

1619
// 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?
20+
//The error is in line 5, the error is occurring because there was a comma missing here; ("," "").
1721

1822
// c) Identify all the lines that are variable reassignment statements
23+
//carPrice = Number(carPrice.replaceAll(",", ""));
24+
//priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",",""));
1925

2026
// d) Identify all the lines that are variable declarations
27+
//let carPrice = "10,000";
28+
//let priceAfterOneYear = "8,543";
29+
//const priceDifference = carPrice - priceAfterOneYear;
30+
//const percentageChange = (priceDifference / carPrice) * 100;
31+
2132

2233
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
34+
//The expression is converting the string representation of the car price to a number by first removing the comma.
35+
36+
//Purpose:
37+
//To allow the computer identify the value of the car price as a number so that it can be used in calculations.

0 commit comments

Comments
 (0)