@@ -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 ;
@@ -20,3 +20,30 @@ console.log(`The percentage change is ${percentageChange}`);
2020// d) Identify all the lines that are variable declarations
2121
2222// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
23+
24+ /*
25+ Answer
26+ a) In this section of the code, we have function calls appear 5 time through out the code. Here is each of them on the line of code that
27+ they are call:
28+ - Number(carPrice.replaceAll(",","")); in line 4 is a function calls because the .replaceALL is being executed
29+ - Number(priceAfterOneYear.replaceAll(",", "")); in line 5 is also a function call because .replaceAll is being executed.
30+ - Inside the Number() function the .replaceAll in both line 4 and 5 is also a function call because the the parent function is also
31+ being executed.
32+ - the console.log is a function calls
33+ So the total amount of function call in this code is 5
34+
35+ b) The main error for the when the running this line of code if for the missing right parameter after the double quote, so fix this
36+ just add the coma right after the double quote.
37+
38+ c) There are 2 reassign variable statement at line 4 and line 5.
39+
40+ d)There are 4 total variable declarations in this code:
41+ - let carPrice = "10,00"; line 1
42+ - let priceAfterOneYear ="8,543"; line 2
43+ - const priceDifference = carPrice - priceAfterOneYear; line 7
44+ - const percentageChange = (priceDifference / carPrice) * 100; line 8
45+
46+ e) The expression Number(carPrice.replaceAll(",","")) are doing 2 main purpose,
47+ - The first purpose is to remove the coma from the string number "10000" and "8543".
48+ - Is the changing the string number to number data type.
49+ */
0 commit comments