@@ -8,13 +8,17 @@ const priceDifference = carPrice - priceAfterOneYear;
88const percentageChange = ( priceDifference / carPrice ) * 100 ;
99
1010console . log ( `The price difference is ${ priceDifference } ` ) ;
11+ < << << << Updated upstream
1112
1213
14+ = = === ==
15+ >>> >>> > Stashed changes
1316console.log(`The percentage change is ${ percentageChange } %`);
1417
1518// Read the code and then answer the questions below
1619
1720// a) How many function calls are there in this file? Write down all the lines where a function call is made
21+ < << << << Updated upstream
1822// Answer: 6 function calls.
1923
2024// 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?
@@ -35,3 +39,32 @@ console.log(`The percentage change is ${percentageChange}%`);
3539// Answer: carPrice.replaceAll(",","") remove commas from the string.
3640// Number(...) changes the text to a number so subtraction and division work correctly.
3741
42+ = = === ==
43+ // Answer: 6 function calls:
44+ // - Line 4: replaceAll(",", "") and Number(...)
45+ // - Line 5: replaceAll(",", "") and Number(...)
46+ // - Line 10: console.log(...)
47+ // - Line 11: console.log(...)
48+
49+ // 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?
50+ // Answer: The error was on the priceAfterOneYear.replaceAll line.
51+ // It was written as replaceAll("," "") which is invalid syntax (missing a comma between the two arguments).
52+ // Fixed by writing replaceAll(",", "") so the arguments are the search string "," and the replacement "".
53+
54+ // c) Identify all the lines that are variable reassignment statements
55+ // Answer:
56+ // - carPrice = Number(carPrice.replaceAll(",", ""));
57+ // - priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));
58+
59+ // d) Identify all the lines that are variable declarations
60+ // Answer:
61+ // - let carPrice = "10,000";
62+ // - let priceAfterOneYear = "8,543";
63+ // - const priceDifference = carPrice - priceAfterOneYear;
64+ // - const percentageChange = (priceDifference / carPrice) * 100;
65+
66+ // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
67+ // Answer:
68+ // carPrice.replaceAll(",", "") removes all commas from the string (e.g. "10,000" becomes "10000").
69+ // Number(...) converts that string into a number (10000) so we can do subtraction and division.
70+ >>> >>> > Stashed changes
0 commit comments