@@ -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,24 @@ 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+ /*
16+ replaceAl() : In line 4, replaceAll(",", "") and in line 5, replaceAll("," "")
17+ Number() : In line 4, Number(carPrice.replaceAll(",", "")) and in line 5, Number(priceAfterOneYear.replaceAll("," "")
18+ console.log: In line 10, console.log(`The percentage change is ${percentageChange}`);
19+ */
1520
1621// 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?
22+ //Basically, the error is coming from line 5. It missed the , between two values.
23+ //priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," , ""));
1724
1825// c) Identify all the lines that are variable reassignment statements
26+ //line 4 and line 5
1927
2028// d) Identify all the lines that are variable declarations
29+ //line 1, line 2, line 7 and line 8
2130
2231// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
32+ /* Number(carPrice.replaceAll(",","")) let's breakdown this to understand.
33+ carPrice.replaceAll(",","") -> replaces , and it becomes 1000
34+ Number("1000") converts string to a number -> 1000.
35+ */
0 commit comments