@@ -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,33 @@ 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 4 function calls here . There are two when you use Number ( ) ;
16+ The other call is about console . log ( ) to print the string out .
17+ When you call the variable ( priceDifference / carPrice ) , it is a function call .
18+ The last one is
1519
1620// 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?
1721
22+ It shows that I miss a ) parenthesis .
23+
24+
1825// c) Identify all the lines that are variable reassignment statements
1926
27+ carPrice = Number ( carPrice . replaceAll ( "," , "" ) ) ;
28+ priceAfterOneYear = Number ( priceAfterOneYear . replaceAll ( "," ""));
29+
2030// d) Identify all the lines that are variable declarations
2131
22- // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
32+ let carPrice = "10,000" ;
33+ let priceAfterOneYear = "8,543" ;
34+
35+ const priceDifference = carPrice - priceAfterOneYear ;
36+ const percentageChange = ( priceDifference / carPrice ) * 100 ;
37+
38+ // e) Describe what is the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
39+
40+ It deletes all the comma insides . I
41+ The Number helps convert that string into an actual figure .
42+
43+
44+
0 commit comments