@@ -12,11 +12,25 @@ 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+ // there are 4 function calls - Replace All is called twice and Number is called twice
16+ // if console.log is considered a function call then there are 5 function calls in total
1517
1618// 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?
19+ // there is a comma missing in line 5 it should be
20+ // priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));
21+ // Replace All requires two arguments which should be separated by a comma, without the comma
22+ // it cannot tell where the first argument ends and the second argument begins
1723
1824// c) Identify all the lines that are variable reassignment statements
25+ // there are 2 variable reassignment statements
26+ // carPrice is reassigned on line 4 - the original value was declared in the let statement on line 1
27+ // priceAfterOneYear is reassigned on line 5 - the original value was declared in the let statement on line 2
1928
2029// d) Identify all the lines that are variable declarations
30+ // variable declarations are where the variable is declared for the first time
31+ // This happens in lines 1, 2 with let statements and in lines 7, 8 with const statements
2132
2233// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
34+ // it replaces the commas in the numbers such as 20,000 so calculations can be done
35+ // with commas the numbers are recognised as a string but with spaces they can be recognised as numbers
36+ // calculations cannot be performed on strings so they need to be converted to numbers
0 commit comments