@@ -2,7 +2,7 @@ let carPrice = "10,000";
22let priceAfterOneYear = "8,543" ;
33
44carPrice = Number ( carPrice . replaceAll ( "," , "" ) ) ;
5- priceAfterOneYear = Number ( priceAfterOneYear . replaceAll ( "," "" ) ) ;
5+ priceAfterOneYear = Number ( priceAfterOneYear . replaceAll ( "," , "" ) ) ;
66
77const priceDifference = carPrice - priceAfterOneYear ;
88const 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+ // 5 function calls
17+ // carPrice = Number(carPrice.replaceAll(",", ""));
18+ // priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));
19+ // console.log(`The percentage change is ${percentageChange}`);
20+
1621// 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?
1722
23+ // Error: SyntaxError: missing ) after argument list
24+ // The error comes from:
25+ // priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));
26+ // Why: The comma between the two arguments of replaceAll() is missing.
27+ // Fix: Add the missing comma:
28+ // priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));
29+
30+
1831// c) Identify all the lines that are variable reassignment statements
1932
33+ // carPrice = Number(carPrice.replaceAll(",", ""));
34+ // priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));
35+
2036// d) Identify all the lines that are variable declarations
2137
38+ // let carPrice = "10,000";
39+ // let priceAfterOneYear = "8,543";
40+ // const priceDifference = carPrice - priceAfterOneYear;
41+ // const percentageChange = (priceDifference / carPrice) * 100;
42+
2243// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
44+
45+ // It removes the comma from the string and converts the resulting string into a number.
0 commit comments