@@ -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,33 @@ 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 5 function calls, 2x (lines 4 and 5), 1x (line 10)
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?
1719
20+
21+ // Error: SyntaxError: missing ) after argument list (Line 5)
22+ // The arguments in the replaceAll function need to be comma separated, the difference can be seen from line 4 where the code
23+ // did not hit an error, adding in that comma will solve the error
24+
1825// c) Identify all the lines that are variable reassignment statements
1926
27+ // Lines 4 and 5
28+
2029// d) Identify all the lines that are variable declarations
2130
31+ // Lines 1, 2, 7 and 8
32+
2233// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
34+
35+ // It looks like the function is removing the commas (by replacing them with nothing) from the string
36+ // so there are only numbers left and then converting it into a Number data type
37+
38+ console . log ( carPrice )
39+
40+ // I commented out the line of code with an error and ran the code to confirm, it returned 10000
41+ // I can check it is a number by running a math operation on it
42+
43+ console . log ( carPrice * 2 )
44+
45+ // result as expected
0 commit comments