@@ -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 ;
@@ -11,12 +11,32 @@ console.log(`The percentage change is ${percentageChange}`);
1111
1212// Read the code and then answer the questions below
1313
14- // a) How many function calls are there in this file? Write down all the lines where a function call is made
14+ // a) How many function calls are there in this file? Write down all the lines where a function call is made?
15+ //There are 5 function calls:
16+ //replaceAll
17+ //Line 4
18+ //Number(...)
19+ //Line 4
20+ //priceAfterOneYear.replaceAll(",", "")
21+ //Line 5
22+ //Number(...)
23+ //Line 5
24+ //console.log
1525
1626// 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?
17-
27+ //missing a comma between the two arguments.
1828// c) Identify all the lines that are variable reassignment statements
29+ //carPrice = Number(carPrice.replaceAll(",", ""));
30+ //priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));
31+
1932
2033// d) Identify all the lines that are variable declarations
34+ //let carPrice
35+ //let priceAfterOneYear
36+ //const priceDifference
37+ //const percentageChange
2138
2239// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
40+ //it removes all commas from the string
41+ //converts the string "10000" into the number 10000
42+ //The purpose is to turn the price from a formatted string into a number
0 commit comments