|
| 1 | +let carPrice = "10,000"; |
| 2 | +let priceAfterOneYear = "8,543"; |
| 3 | + |
| 4 | +carPrice = Number(carPrice.replaceAll(",", "")); |
| 5 | +priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",","")); |
| 6 | + |
| 7 | +const priceDifference = carPrice - priceAfterOneYear; |
| 8 | +const percentageChange = (priceDifference / carPrice) * 100; |
| 9 | + |
| 10 | +console.log(`The percentage change is ${percentageChange}`); |
| 11 | + |
| 12 | +// Read the code and then answer the questions below |
| 13 | + |
| 14 | +// a) How many function calls are there in this file? Write down all the lines where a function call is made |
| 15 | +/* there has five function in line 4 and and console . log also has one |
| 16 | +line 4 and 5 has two Number() function |
| 17 | +line 4 and 5 has two replaceALL() function |
| 18 | +line 10 has one console . log () |
| 19 | + |
| 20 | +/* 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? |
| 21 | + In line five error shown in replaceAll("," "")); missing comma before last two comma(",",""). |
| 22 | + |
| 23 | +/* c) Identify all the lines that are variable reassignment statements |
| 24 | +line 4 carPrice = Number(carPrice.replaceAll(",", "")); |
| 25 | +line 5 priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); |
| 26 | +As per the carPrice and priceAfterOneYear has been declared in line 1 and 2 by using let variable. |
| 27 | + |
| 28 | +/*d) Identify all the lines that are variable declarations |
| 29 | +line 1 let carPrice = "10,000"; |
| 30 | +line 2 let priceAfterOneYear = "8,543"; |
| 31 | +line 7 const priceDifference = carPrice - priceAfterOneYear; |
| 32 | +line 8 const percentageChange = (priceDifference / carPrice) * 100; |
| 33 | + |
| 34 | +/* e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? |
| 35 | +replaceALL throwout all the commas from the string and number became numerical value. |
0 commit comments