Skip to content

Commit 7a0b1f7

Browse files
committed
update: Fix minor formatting issues in comments and clarify variable reassignment in percentage change calculation
1 parent 4a786db commit 7a0b1f7

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ 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;
@@ -12,11 +12,23 @@ 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-
15+
// There are 5 function calls in this file. The code consists of variable assignments and calculations without any function definitions or calls.
16+
// replaceAll(",", "") (twice)
17+
// Number(...) (twice)
18+
// console.log(...) (once)
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+
// There are no errors in the code. The code runs successfully and calculates the percentage change in car price without any issues.
1721

1822
// c) Identify all the lines that are variable reassignment statements
23+
// The variable reassignment statements are:
24+
// 1. carPrice = Number(carPrice.replaceAll(",", ""));
25+
// 2. priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));
1926

2027
// d) Identify all the lines that are variable declarations
21-
28+
// The variable declarations are:
29+
// 1. let carPrice = "10,000";
30+
// 2. let priceAfterOneYear = "8,543";
31+
// 3. const priceDifference = carPrice - priceAfterOneYear;
32+
// 4. const percentageChange = (priceDifference / carPrice) * 100;
2233
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
34+
// The expression `Number(carPrice.replaceAll(",", ""))` is converting the string representation of the car price, which includes commas (e.g., "10,000"), into a number. The `replaceAll(",", "")` part removes all commas from the string, resulting in "10000", and then the `Number()` function converts this string into a numeric value (10000). This is necessary for performing arithmetic operations on the price.

0 commit comments

Comments
 (0)