@@ -12,11 +12,37 @@ 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
16+ //carPrice.replaceAll(",", "")
17+ //Number(carPrice.replaceAll(",", ""))
18+ //priceAfterOneYear.replaceAll(",", "")
19+ //Number(priceAfterOneYear.replaceAll(",", ""))
20+ //console.log(`The percentage change is ${percentageChange}`)
1521
1622// 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?
23+ //priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));
1724
1825// c) Identify all the lines that are variable reassignment statements
26+ //priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); missing a comma between the two arguments of replaceAll()
1927
20- // d) Identify all the lines that are variable declarations
2128
22- // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
29+ // d) Identify all the lines that are variable declarations
30+ // let carPrice = "10,000";
31+ //let priceAfterOneYear = "8,543";
32+ //const priceDifference = carPrice - priceAfterOneYear;
33+ //const percentageChange = (priceDifference / carPrice) * 100;
34+
35+ // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
36+ //carPrice.replaceAll(",", ""), "10,000" and removes the comma:"10000"
37+ //Number("10000") converts the string "10000" into the number:10000
38+ //So the whole expression:Number(carPrice.replaceAll(",", ""))converts "10,000"
39+ //from a string containing a comma into the actual number 10000.
40+ //"10,000"
41+ // ↓
42+ //remove ","
43+ // ↓
44+ // //"10000"
45+ // ↓
46+ // convert to Number
47+ // ↓
48+ // 10000
0 commit comments