@@ -12,11 +12,26 @@ 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+ carPrice = Number ( carPrice . replaceAll ( "," , "" ) ) ;
16+ priceAfterOneYear = Number ( priceAfterOneYear . replaceAll ( "," "" ) ) ;
17+ console . log ( `The percentage change is ${ percentageChange } ` ) ;
18+
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?
21+ priceAfterOneYear = Number ( priceAfterOneYear . replaceAll ( "," "" ) ) ;
22+ fix ;
23+ priceAfterOneYear = Number ( priceAfterOneYear . replaceAll ( "," , "" ) ) ;
1724
1825// c) Identify all the lines that are variable reassignment statements
26+ carPrice = Number ( carPrice . replaceAll ( "," , "" ) ) ;
27+ priceAfterOneYear = Number ( priceAfterOneYear . replaceAll ( "," "" ) ) ;
1928
2029// d) Identify all the lines that are variable declarations
30+ let carPrice = "10,000" ;
31+ let priceAfterOneYear = "8,543" ;
32+
2133
2234// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
35+ replaceAll gets rid of the commas → "10,000" becomes "10000" .
36+ Number ( ) turns that string into the number 10000.
37+ so we can do maths with it .
0 commit comments