Skip to content

Commit 0fad45e

Browse files
answered Qs with updates notes fixed syntax error to ensure code runs as expected
1 parent 846928b commit 0fad45e

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

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

Lines changed: 24 additions & 1 deletion
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;
@@ -13,10 +13,33 @@ console.log(`The percentage change is ${percentageChange}`);
1313

1414
// a) How many function calls are there in this file? Write down all the lines where a function call is made
1515

16+
// Function calls are determined by the presence of parentheses "()" after a function name.
17+
// Therefore in this file, there are 6 function calls:
18+
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?
1720

21+
// The error is occurring on line 5:
22+
// SyntaxError: missing ) after argument list. This is because there is a missing comma between the two arguments
23+
// (search value & replace value) in the replaceAll function.
24+
// To fix this problem, we can add a comma between the two arguments.
25+
1826
// c) Identify all the lines that are variable reassignment statements
1927

28+
// These lines include:
29+
// line 3: let carPrice = "10,000"; to carPrice = Number(carPrice.replaceAll(",", ""));
30+
// line 4: let priceAfterOneYear = "8,543"; to priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));
31+
2032
// d) Identify all the lines that are variable declarations
2133

34+
// These lines include:
35+
// line 3: let carPrice = "10,000";
36+
// line 4: let priceAfterOneYear = "8,543";
37+
// line 6: const priceDifference = carPrice - priceAfterOneYear;
38+
// line 7: const percentageChange = (priceDifference / carPrice) * 100;
39+
2240
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
41+
42+
// The purpose of this is expression is to search for remove all commas from the string value of carPrice and replace them with an empty string.
43+
// This converts the CarPrice value from a string to a type number, which we can now perform mathematical operations on.
44+
// Since the purpose of this program is to calculate the percentage change in the price of a car.
45+
// We need type number values to perform the necessary calculations.

0 commit comments

Comments
 (0)