@@ -11,12 +11,41 @@ console.log(`The percentage change is ${percentageChange}`);
1111
1212// Read the code and then answer the questions below
1313
14+ // --- Answers to the questions ---
15+
1416// a) How many function calls are there in this file? Write down all the lines where a function call is made
1517
18+ // Function calls:
19+ // - Line 4: carPrice.replaceAll(",", "")
20+ // - Line 4: Number(...)
21+ // - Line 5: priceAfterOneYear.replaceAll("," "") --> syntax error here
22+ // - Line 5: Number(...)
23+ // - Line 10: console.log(...)
24+
1625// 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?
1726
27+ // Error at line 5: SyntaxError due to missing comma in replaceAll arguments
28+ // Fix: add the missing comma inside replaceAll:
29+ // priceAfterOneYear.replaceAll(",", "")
30+
1831// c) Identify all the lines that are variable reassignment statements
1932
33+ // Reassignments:
34+ // - Line 4: carPrice = Number(...)
35+ // - Line 5: priceAfterOneYear = Number(...)
36+
2037// d) Identify all the lines that are variable declarations
2138
39+ // Declarations:
40+ // - Line 1: let carPrice = "10,000";
41+ // - Line 2: let priceAfterOneYear = "8,543";
42+ // - Line 7: const priceDifference = ...
43+ // - Line 10: const percentageChange = ...
44+
2245// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
46+
47+ // Explanation:
48+ // - carPrice.replaceAll(",","") removes all commas from the string "10,000", turning it into "10000".
49+ // - Number(...) converts the resulting string "10000" into the numeric value 10000.
50+ // This allows mathematical operations on carPrice, which is originally a formatted string.
51+
0 commit comments