@@ -2,21 +2,63 @@ 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 ;
99
10- console . log ( `The percentage change is ${ percentageChange } ` ) ;
10+ console . log ( `The percentage change is ${ percentageChange } % ` ) ;
1111
1212// Read the code and then answer the questions below
1313
14+
15+
1416// a) How many function calls are there in this file? Write down all the lines where a function call is made
1517
18+ /*There are four function calls in total: two in the line
19+
20+ carPrice = Number(carPrice.replaceAll(",", ""));
21+
22+ and two in the line
23+
24+ priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));
25+
26+ In each line, one function is nested inside the other, so both lines contain two function calls each.*/
27+
28+
29+
1630// 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?
1731
32+
33+ /*priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));
34+ ^^^
35+
36+ SyntaxError: missing ) after argument list
37+ the error is because a missing comma in the replaceAll method argument list
38+ */
39+
40+
1841// c) Identify all the lines that are variable reassignment statements
1942
43+
44+
45+ /*carPrice = Number(carPrice.replaceAll(",", ""));
46+ priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));
47+ these two lines are variable reassignment statements because we are reassigning a new value to the existing variables carPrice and priceAfterOneYear.*/
48+
2049// d) Identify all the lines that are variable declarations
2150
51+
52+ /*let carPrice = "10,000";
53+ let priceAfterOneYear = "8,543";
54+ const priceDifference = carPrice - priceAfterOneYear;
55+ const percentageChange = (priceDifference / carPrice) * 100;
56+
57+ these four lines are variable declaration statements because we are declaring new variables:
58+ carPrice, priceAfterOneYear, priceDifference and percentageChange using let and const keywords.*/
59+
60+
61+
2262// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
63+
64+ /*first removes all commas from the string carPrice using replaceAll(",", ""), and then converts the resulting string into a number using Number().*/
0 commit comments