@@ -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,24 @@ 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 five function calls in this file, the lines where a call function is made are as follows:
16+ // line 4, replaceAll()
17+ // line 4, Number()
18+ // line 5, replaceAll()
19+ // line 5, Number()
20+ // line 10, console.log()
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+ // the error is coming from line 5
24+ // it is a syntax error, the expression priceAfterOneYear.replaceAll("," "") ismissing a comma
25+ // to fix this problem we add comma between the two arguments
1726
1827// c) Identify all the lines that are variable reassignment statements
28+ // the lines that are variable reassignment statements: -line 4 -line 5
1929
2030// d) Identify all the lines that are variable declarations
31+ // the lines that are variable declarations: -line 1 -line 2 -line 7 -line 8
2132
2233// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
34+ // the expression calls the replace method to replace the comma with empty string
35+ // converting the new string to a number to be able to perform math operations
0 commit comments