@@ -20,3 +20,31 @@ console.log(`The percentage change is ${percentageChange}`);
2020// d) Identify all the lines that are variable declarations
2121
2222// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
23+
24+ // Answers:
25+ /*a) in total there are 5 function calls in the file:
26+ carPrice.replaceAll(",", "")
27+ Number(carPrice.replaceAll(",", ""))
28+ priceAfterOneYear.replaceAll(",", "")
29+ Number(priceAfterOneYear.replaceAll(",", ""))
30+ console.log(...) */
31+
32+ /* b) The problem is on line 5. replaceAll is missing the comma between its
33+ two inputs, so JavaScript can’t read it properly. Once I add the comma,
34+ the function works normally. correct version (priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));*/
35+
36+ /* c) The reassignment statements are:
37+ -carPrice = Number(carPrice.replaceAll(",", ""));
38+ -priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); */
39+
40+ /* d) The variable declaration are:
41+ -let carPrice = "10,000";
42+ -let priceAfterOneYear = "8,543";
43+ -const priceDifference = carPrice - priceAfterOneYear;
44+ -const percentageChange = (priceDifference / carPrice) * 100; */
45+
46+ /* e) the expression Number(carPrice.replaceAll(",","")) removes the commas from the price string
47+ and then converts it into a number. This is done so the price can be used in
48+ calculations like subtraction and division. */
49+
50+
0 commit comments