@@ -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,23 @@ 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+
16+ // Ans: There are five (5) function calls, Line 4 Number() and replaceAll(), Line 5, Number() and replaceAll()
17+ // Line 10 log().
1518
1619// 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?
1720
21+ // Ans: The error is coming from line 5 "("," ""));"" a comma was missing. Putting a comma solved the problem.
22+
1823// c) Identify all the lines that are variable reassignment statements
24+
25+ // Ans: Line 4 carPrice and Line 5 priceAfterOneyear are variable reassignments.
1926
2027// d) Identify all the lines that are variable declarations
2128
29+ // Ans: 4 variable declaration Line 1, Line 2, Line 7 and Line 8
30+
2231// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
32+
33+ // Ans: The purpose of the expression Number(carPrice.replaceAll(",","")) is to change a string argument the contains commas passed to replaceAll()
34+ // function into number, first the function replaceAll() removes the commas and then the function Number() changes it into number.
0 commit comments