@@ -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,19 @@ 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+ // carPrice = Number(carPrice.replaceAll(",", ""));
17+ // priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));
18+ // both use a call to read the string as a number and to replaceAll the comas with a null value
19+
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 is on line 5 there should be a coma after the "," to make the change
1723
1824// c) Identify all the lines that are variable reassignment statements
25+ // lines 5 and 6 reassign the variables from the string to a number so that we can do a calculation on it
1926
2027// d) Identify all the lines that are variable declarations
28+ // lines 1, 2, 7 and 8
2129
2230// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
31+ // it is changing the string "10,000" to a number and removing the comma so it can be used in the calculation
0 commit comments