@@ -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 ;
@@ -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+ // Line 4: Number(), carPrice.replaceAll(",", "") - 2 function calls
16+ // Line 5: Number(), priceAfterOneYear.replaceAll(",", "") - 2 function calls
17+ // Line 10: console.log() - 1 function call
18+ // In total: 5 function calls
1519
1620// 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?
21+ // Its line 5 - missed comma in replaceAll method. Fixed now - added comma after the first parameter.
1722
1823// c) Identify all the lines that are variable reassignment statements
24+ // Line 4: carPrice = Number(carPrice.replaceAll(",", ""));
25+ // Line 5: priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));
1926
2027// d) Identify all the lines that are variable declarations
28+ // Line 1: let carPrice = "10,000";
29+ // Line 2: let priceAfterOneYear = "8,543";
30+ // Line 7: const priceDifference = carPrice - priceAfterOneYear;
31+ // Line 8: const percentageChange = (priceDifference / carPrice) * 100;
2132
2233// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
34+ // This expression transforms data type from String to Number and removes all commas from the String value of carPrice, so "10,000" becomes "10000".
0 commit comments