@@ -12,11 +12,28 @@ 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 5 function calls in this file. They occur on the following 3 lines:
16+ // carPrice = Number(carPrice.replaceAll(",", ""));
17+ // priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));
18+ // console.log(`The percentage change is ${percentageChange}`);
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+ // The code contains one syntax error on the following line:
22+ // priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));
23+ // A comma is missing between the arguments inside replaceAll(). It should be:
24+ // priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));
1725
1826// c) Identify all the lines that are variable reassignment statements
27+ // The lines that are variable reassignment statements are as follows:
28+ // carPrice = Number(carPrice.replaceAll(",", ""));
29+ // priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));
1930
2031// d) Identify all the lines that are variable declarations
32+ // The lines that contain variable declarations are as follows:
33+ // let carPrice = "10,000";
34+ // let priceAfterOneYear = "8,543";
35+ // const priceDifference = carPrice - priceAfterOneYear;
36+ // const percentageChange = (priceDifference / carPrice) * 100;
2137
2238// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
39+ // It removes the comma from the car price string and converts it into a number so it can be used in calculations.
0 commit comments