@@ -2,21 +2,31 @@ 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 ;
99
1010console . log ( `The percentage change is ${ percentageChange } ` ) ;
11-
12- // Read the code and then answer the questions below
13-
14- // a) How many function calls are there in this file? Write down all the lines where a function call is made
15-
16- // 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?
17-
18- // c) Identify all the lines that are variable reassignment statements
19-
20- // d) Identify all the lines that are variable declarations
21-
22- // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
11+ // a) There are 5 function calls.
12+ // carPrice.replaceAll(",", "")
13+ // Number(carPrice.replaceAll(",", ""))
14+ // priceAfterOneYear.replaceAll(",", "")
15+ // Number(priceAfterOneYear.replaceAll(",", ""))
16+ // console.log(`The percentage change is ${percentageChange}`)
17+
18+ // b) The error is on line 5 because there is a missing comma between "," and "".
19+ // It should be replaceAll(",", "").
20+
21+ // c) The variable reassignment statements are:
22+ // carPrice = Number(carPrice.replaceAll(",", ""));
23+ // priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));
24+
25+ // d) The variable declarations are:
26+ // let carPrice = "10,000";
27+ // let priceAfterOneYear = "8,543";
28+ // const priceDifference = carPrice - priceAfterOneYear;
29+ // const percentageChange = (priceDifference / carPrice) * 100;
30+
31+ // e) Number(carPrice.replaceAll(",", "")) removes the comma from the carPrice string
32+ // and then converts the result from a string into a number.
0 commit comments