@@ -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 ;
@@ -12,27 +12,11 @@ console.log(`The percentage change is ${percentageChange}`);
1212// Read the code and then answer the questions below
1313
1414// a) How many function calls are there in this file? Write down all the lines where a function call is made
15- //1-carPrice.replaceAll(",", "") in line 4
16- //3-number(...) in line 4 - enumerate the first result of replaceAll
17- //2-priceAfterOneYear.replaceAll("," ,"")) in line 5
18- //4-number(...) in line 5 - enumerate the second result of replaceAll
19- //5-console.log(..) - line 9
20-
2115
2216// 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?
23- // the error is : a syntax error coming from the missing comma in line 5 between the arguments
24-
25-
2617
2718// c) Identify all the lines that are variable reassignment statements
28- // const priceDifference = carPrice - priceAfterOneYear; Line 7
29- // const percentageChange = (priceDifference / carPrice) * 100; Line 8
3019
3120// d) Identify all the lines that are variable declarations
32- // carPrice = Number(carPrice.replaceAll(",", "")); Line 4
33- // priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); Line 5
3421
3522// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
36- // the number function convert the enumerate a string to a number and the method replaceAll replace ever comma with a space
37- // the purpose is to clean the value so that it can be converted to a proper number using Number().
38-
0 commit comments