Skip to content

Commit 623bd7d

Browse files
committed
Clarify explanation to reflect the word "Argument" and Refactor comments for clarity and consistency in percentage change calculations
1 parent 209b644 commit 623bd7d

1 file changed

Lines changed: 22 additions & 23 deletions

File tree

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

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,34 @@ 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-
There are five function calls in this file. The lines where function calls are made are:
16-
1. Line 4: carPrice.replaceAll(",", "")
17-
2. Line 5: priceAfterOneYear.replaceAll(",", "")
18-
3. Line 7: Number(carPrice.replaceAll(",", ""))
19-
4. Line 8: Number(priceAfterOneYear.replaceAll(",", ""))
20-
5. Line 10: console.log()
15+
//There are five function calls in this file. The lines where function calls are made are:
16+
//1. Line 4: carPrice.replaceAll(",", "")
17+
//2. Line 5: priceAfterOneYear.replaceAll(",", "")
18+
//3. Line 7: Number(carPrice.replaceAll(",", ""))
19+
//4. Line 8: Number(priceAfterOneYear.replaceAll(",", ""))
20+
//5. Line 10: console.log()
2121

2222
// 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?
2323

24-
The error is occurring on line 5 because a comma is missing between the arguments in the replaceAll function, to fix the problem,
25-
we need to include the "," character in the replaceAll function like this: priceAfterOneYear.replaceAll(",", "")
24+
//The error is occurring on line 5 because a comma is missing between the arguments in the replaceAll function, to fix the problem,
25+
//we need to include the "," character in the replaceAll function like this: priceAfterOneYear.replaceAll(",", "")
2626

2727
// c) Identify all the lines that are variable reassignment statements
2828

29-
The lines that are variable reassignment statements are:
30-
1. Line 4: carPrice = Number(carPrice.replaceAll(",", ""));
31-
2. Line 5: priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));
29+
//The lines that are variable reassignment statements are:
30+
//1. Line 4: carPrice = Number(carPrice.replaceAll(",", ""));
31+
//2. Line 5: priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));
3232

3333
// d) Identify all the lines that are variable declarations
34-
The lines that are variable declarations are:
35-
1. Line 1: let carPrice = "10,000";
36-
2. Line 2: let priceAfterOneYear = "8,543";
37-
3. Line 6: const priceDifference = carPrice - priceAfterOneYear;
38-
4. Line 7: const percentageChange = (priceDifference / carPrice) * 100;
39-
34+
//The lines that are variable declarations are:
35+
//1. Line 1: let carPrice = "10,000";
36+
//2. Line 2: let priceAfterOneYear = "8,543";
37+
//3. Line 6: const priceDifference = carPrice - priceAfterOneYear;
38+
//4. Line 7: const percentageChange = (priceDifference / carPrice) * 100;
4039
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
41-
The expression "Number(carPrice.replaceAll(",", ""))" is performing two main operations:
42-
1. "carPrice.replaceAll(",", "")": This part of the expression removes all commas from the string representation of
43-
"carPrice". For example, it converts "10,000" to "10000".
44-
2. "Number(priceAfterOneYear.replaceAll(",", ""));": This part converts the resulting string (after removing commas)
45-
into a numeric value. The purpose of this expression is to convert the string representation of a number that
46-
may contain commas into an actual numeric value that can be used for mathematical calculations.
40+
//The expression "Number(carPrice.replaceAll(",", ""))" is performing two main operations:
41+
//1. "carPrice.replaceAll(",", "")": This part of the expression removes all commas from the string representation of
42+
//"carPrice". For example, it converts "10,000" to "10000".
43+
//2. "Number(priceAfterOneYear.replaceAll(",", ""));": This part converts the resulting string (after removing commas)
44+
//into a numeric value. The purpose of this expression is to convert the string representation of a number that
45+
//may contain commas into an actual numeric value that can be used for mathematical calculations.

0 commit comments

Comments
 (0)