@@ -12,11 +12,20 @@ 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+ // 6 function calls: Line 4 (replaceAll, Number), Line 5 (replaceAll, Number), Line 10 (console.log)
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+ // SyntaxError on line 5: missing comma between arguments "," and ""
19+ // Fix: priceAfterOneYear.replaceAll(",", "")
1720
1821// c) Identify all the lines that are variable reassignment statements
22+ // Line 4: carPrice = Number(carPrice.replaceAll(",", ""));
23+ // Line 5: priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));
1924
2025// d) Identify all the lines that are variable declarations
26+ // Line 1: let carPrice, Line 2: let priceAfterOneYear, Line 7: const priceDifference, Line 8: const percentageChange
2127
2228// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
29+ // Converts string with commas ("10,000") to number (10000) for mathematical calculations
30+ // replaceAll(",", "") removes commas, Number() converts string to number
31+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll
0 commit comments