@@ -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,11 +12,29 @@ 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+ // -) functions called are:
16+ // Number() ||| carPrice = Number(carPrice.replaceAll(",", ""));
17+ // Number() ||| priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));
18+ // replaceAll() ||| carPrice = Number(carPrice.replaceAll(",", ""));
19+ // replaceAll() ||| priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));
20+ // console.log()||| console.log(`The percentage change is ${percentageChange}`);
1521
1622// 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 coming from line: 5.
24+ // This error is occurring because a , is missing inside the replaceAll() so the two inputs aren't separated.
25+ // I will fix this error by adding , after the first input inside replaceAll()
26+ // replaceAll("," "") Changed to >>
27+ // replaceAll(",", "")
1728
1829// c) Identify all the lines that are variable reassignment statements
30+ // Line 4
31+ // Line 5
1932
2033// d) Identify all the lines that are variable declarations
34+ // Line 1
35+ // Line 2
36+ // Line 7
37+ // Line 8
2138
2239// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
40+ // it replaces the , that is inside the number with nothing ( removes the , from the number)
0 commit comments