11let carPrice = "10,000" ;
22let priceAfterOneYear = "8,543" ;
33
4- carPrice = Number ( carPrice . replaceAll ( "," , "" ) ) ;
5- priceAfterOneYear = Number ( priceAfterOneYear . replaceAll ( "," "" ) ) ;
4+ carPrice = Number ( carPrice . replaceAll ( "," , "" ) ) ;
5+ priceAfterOneYear = Number ( priceAfterOneYear . replaceAll ( "," , "" ) ) ;
66
77const priceDifference = carPrice - priceAfterOneYear ;
88const percentageChange = ( priceDifference / carPrice ) * 100 ;
@@ -13,10 +13,27 @@ 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+ //There are three function calls: replaceAll() - used twice, number() - used twice, console.log() - used once.
17+ // carPrice = Number(carPrice.replaceAll("," , ""));
18+ // priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," , ""));
19+ // console.log(`The percentage change is ${percentageChange}`);
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?
1722
23+ //There was a syntax error on line five, missing comma. Fixed by adding one.
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
32+ //let carPrice = "10,000";
33+ //let priceAfterOneYear = "8,543";
34+ //const priceDifference = carPrice - priceAfterOneYear;
35+ //const percentageChange = (priceDifference / carPrice) * 100;
36+
2237// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
38+
39+ // It's removing the commas, since javascript will recognise 10,000 as a string not a number.
0 commit comments