@@ -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 ;
@@ -13,10 +13,19 @@ 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+ // Answer: Line 4 'Number(), replaceAll()', line 5 'Number(), replaceAll()' and line 8, 100
17+
1618// 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?
19+ // Answer: The error is coming from line 5, spotting at the Number(priceAfterOneYear.replaceAll("," ""));
20+ // // It's a synthax error missing a comma
1721
1822// c) Identify all the lines that are variable reassignment statements
1923
24+ // Answer: Line 4 and 5 are variable assignment statements
25+
2026// d) Identify all the lines that are variable declarations
2127
28+ // Answer: Line 1,2,7 and 8 are variable declearations
29+
2230// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
31+ // Answer: ReplaceAll() function clears out all the commas in the strings, the number() converts the strings to numbers to help with calculation
0 commit comments