@@ -12,11 +12,26 @@ 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 the code:
1516
1617// 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?
18+ // The original code has an error here:
19+ //line 5 : It should be: replaceAll(",", "")
20+ // There is also another problem: carPrice and priceAfterOneYear
21+ // are declared with const, so they cannot be reassigned.
22+ // They should be declared with let if we want to reassign them.
1723
1824// c) Identify all the lines that are variable reassignment statements
25+ // carPrice = Number(carPrice.replaceAll(",", ""));
26+ // priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));
1927
2028// d) Identify all the lines that are variable declarations
29+ // const carPrice = "10,000";
30+ // const priceAfterOneYear = "8,543";
31+ // const priceDifference = carPrice - priceAfterOneYear;
32+ // const percentageChange = (priceDifference / carPrice) * 100;
2133
2234// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
35+ // First, replaceAll(",", "") removes the comma from "10,000", producing the string "10000".
36+ // Then Number() converts the string "10000" into the number 10000.
37+ // This is necessary so that we can perform mathematical calculations with the price.
0 commit comments