@@ -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 ;
@@ -12,11 +12,19 @@ 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+ // 5 functions calls. They are on lines, 4, 5, and 10
1516
1617// 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?
18+ // There was a comma missing in line 5 in replaceAll("," ""). This was needed because replaceAll is a
19+ // function that takes two arguments. The missing comma caused a syntax error.
1720
1821// c) Identify all the lines that are variable reassignment statements
22+ // Lines 4 and 5 are variable reassignment statements where carPrice and priceAfterOneYear are
23+ // reassigned new values.
1924
2025// d) Identify all the lines that are variable declarations
26+ // Lines 1, 2, 7 and 8 are variable declarations where carPrice and priceAfterOneYear are declared.
2127
2228// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
29+ // Number(carPrice.replaceAll(",", "")) removes all commas from the string carPrice and then converts it to a
30+ // number.
0 commit comments