@@ -20,3 +20,35 @@ 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+ //a: There are three function calls, which are: Number(...), replaceAll(...) and console.log(...)
25+ // Function call lines: 1. carPrice = Number(carPrice.replaceAll(",", ""));
26+ // 2. priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));
27+ // 3. console.log(`The percentage change is ${percentageChange}`);
28+
29+ //b: priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")) has an error,SyntaxError: Unexpected string
30+ // missing a comma between the arguments of replaceAll.
31+ // correct is: priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",",""));
32+
33+ // c: two reassignment statements: 1.carPrice = Number(carPrice.replaceAll(",", ""));
34+ // 2.priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));
35+
36+ // d: four variable declarations(using let or cost to declare new variables):
37+ // 1. let carPrice = "10,000";
38+ // 2. let priceAfterOneYear = "8,543";
39+ // 3. const priceDifference = carPrice - priceAfterOneYear;
40+ // 4.const percentageChange = (priceDifference / carPrice) * 100;
41+
42+ //e: 1.carPrice is a string like "10,000"
43+ // 2.replaceAll(",", "") removes commas → becomes "10000"
44+ // 3.Number(...) converts the string "10000" into the number 10000
45+ // The purpose is to convert a currency string with commas (e.g., "10,000") into a usable number (10000) for math calculations.
46+
47+
48+
49+
50+
51+
52+
53+
54+
0 commit comments