@@ -12,11 +12,30 @@ 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. The lines where a function call is made are:
16+ // Line 1: carPrice.replaceAll(",", "")
17+ // Line 2: priceAfterOneYear.replaceAll(",", "")
18+ // Line 3: Number(carPrice.replaceAll(",", ""))
19+ // Line 4: Number(priceAfterOneYear.replaceAll(",", ""))
20+ // Line 5: console.log(`The percentage change is ${percentageChange}`)
1521
1622// 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?
23+ // The error is occurring in line 5, because it's missing a comma between the two arguments of the replaceAll method.
24+ // to fix this problem, we can add a comma between the two arguments: priceAfterOneYear.replaceAll(",", "")
1725
1826// c) Identify all the lines that are variable reassignment statements
27+ // there are 2 variable reassignment statements in this file. The lines where a variable reassignment is made are:
28+ // Line 4 and 5 where we are reassigning new values to the variables
29+ // carPrice and priceAfterOneYear after converting them to numbers and removing the commas.
1930
2031// d) Identify all the lines that are variable declarations
32+ // there are 4 variable declarations in this file. The lines where a variable declaration is made are:
33+ // Line 1: let carPrice = "10,000";
34+ // Line 2: let priceAfterOneYear = "8,543";
35+ // Line 6: const priceDifference = carPrice - priceAfterOneYear;
36+ // Line 7: 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+ // To remove the commas from the string carPrice and convert the resulting string to a number.
40+ // Then, the Number function is used to convert the resulting string into a number data type,
41+ // which can be used for mathematical operations.
0 commit comments