@@ -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 ;
@@ -13,10 +13,21 @@ console.log(`The percentage change is ${percentageChange}`);
1313
1414// a) How many function calls are there in this file? Write down all the lines where a function call is made
1515
16+ //There are 5 function call in this code.
17+ // 1. Line 4 has 2 function call, .replaceAll() and Number()
18+ //2. Line 5 ditto line 4
19+ // 3. line 10 console.log() that logs the result to the console
20+
1621// 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?
22+ // The error in this code is coming from line 5. The wrong use of the replaceAll syntax without a separator.
23+ // I will fix this problem by reading the documentation, to see the right way the syntax should be written.
24+ //Then i will add the comma where necessary
1725
1826// c) Identify all the lines that are variable reassignment statements
27+ // line 4 and 5 are variable reassignment
1928
2029// d) Identify all the lines that are variable declarations
30+ // line 1,2,7,8 are all variable declaration
2131
2232// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
33+ // this expression replaces the comma at the string with an empty string and the convert the string data type to a number data type
0 commit comments