@@ -2,7 +2,7 @@ let carPrice = "10,000";
22let priceAfterOneYear = "8,543" ;
33
44carPrice = Number ( carPrice . replaceAll ( "," , "" ) ) ;
5- priceAfterOneYear = Number ( priceAfterOneYear . replaceAll ( "," "" ) ) ;
5+ priceAfterOneYear = Number ( priceAfterOneYear . replaceAll ( "," , "" ) ) ;
66
77const priceDifference = carPrice - priceAfterOneYear ;
88const percentageChange = ( priceDifference / carPrice ) * 100 ;
@@ -11,12 +11,41 @@ console.log(`The percentage change is ${percentageChange}`);
1111
1212// Read the code and then answer the questions below
1313
14+
15+
1416// a) How many function calls are there in this file? Write down all the lines where a function call is made
1517
18+ // 4 function calls are made.
19+ // Line 4 calls function replaceAll and Number
20+ // Line 5 calls functions replaceAll and Number
21+
22+
23+
1624// 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?
1725
26+ // There is a syntax error. The error says a closing parenthesis is missing, which I think is triggered
27+ // because a comma in the argument list is missing. I added the comma and the error is resolved.
28+
29+
30+
1831// c) Identify all the lines that are variable reassignment statements
1932
33+ // Line 4 reassigning carPrice
34+ // Line 5 reassigning priceAfterOneYear
35+
36+
37+
2038// d) Identify all the lines that are variable declarations
2139
40+ // Line 1 declares carPrice with let
41+ // Line 2 declares priceAfterOneYear with let
42+ // Line 7 declares priceDifference with const
43+ // Line 8 declares percentageChange with const
44+
45+
46+
2247// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
48+
49+ // The original carPrice is a string. In order to do math and get a percentage the string needs to be converted
50+ // into a number first. And before that the string's comma needs to be removed (it's replaced with nothing
51+ // using replaceAll)
0 commit comments