@@ -2,7 +2,8 @@ let carPrice = "10,000";
22let priceAfterOneYear = "8,543" ;
33
44carPrice = Number ( carPrice . replaceAll ( "," , "" ) ) ;
5- priceAfterOneYear = Number ( priceAfterOneYear . replaceAll ( "," "" ) ) ;
5+ //priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));
6+ priceAfterOneYear = Number ( priceAfterOneYear . replaceAll ( "," , "" ) ) ;
67
78const priceDifference = carPrice - priceAfterOneYear ;
89const percentageChange = ( priceDifference / carPrice ) * 100 ;
@@ -20,3 +21,21 @@ console.log(`The percentage change is ${percentageChange}`);
2021// d) Identify all the lines that are variable declarations
2122
2223// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
24+
25+ // Answer
26+
27+ // a) In this file we can say we have 5 function calls (2 function calls & 3 method calls to be specific) and they are in line 4, 5 and 10
28+
29+ // b) When we run the code the error is generating from line 5 and the reason is that when we pass more than 1 argument
30+ // in a method we need to separate them with comma, but in line 5 there is no comma to separate the arguments
31+ // we can fix it by adding a comma to separate the arguments
32+
33+ // c) Lines 4 and 5 are reassignment statements
34+
35+ // d) Lines 1, 2, 7 and 8 are variable declarations
36+
37+ // e) The expression Number(carPrice.replaceAll(",",""))
38+ // 1. carPrice.replaceAll(",","") this method is removing the "," from the String variable carPrice by replacing the "," with empty String which is ""
39+ // all left then is just the String digits without ","
40+ // 2. Number("String digit without comma") and this function converts the String digit to number digit
41+ // and finally Number(carPrice.replaceAll(",","")) expression gives us number
0 commit comments