You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -12,11 +12,18 @@ console.log(`The percentage change is ${percentageChange}`);
12
12
// Read the code and then answer the questions below
13
13
14
14
// a) How many function calls are there in this file? Write down all the lines where a function call is made
15
+
// There are 5 function calls. In the fourth line Number () and replaceAll ().
16
+
// In the fifth line same as line 4 Number () and replaceAll ().
17
+
// Last one in seventh line console.log ().
15
18
16
19
// 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?
20
+
// The error is in line 5. The error is occurring because there is a missing comma in the replaceAll function. The correct code should be: priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));
17
21
18
22
// c) Identify all the lines that are variable reassignment statements
23
+
// Line 4 and line 5 are variable reassignment statements. In line 4, carPrice is being reassigned with the new value after removing the comma and converting it to a number. In line 5, priceAfterOneYear is being reassigned in the same way.
19
24
20
25
// d) Identify all the lines that are variable declarations
26
+
// Line 1 and line 2 are variable declarations. In line 1, carPrice is declared and initialized with the string value "10,000". In line 2, priceAfterOneYear is declared and initialized with the string value "8,543".
21
27
22
28
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
29
+
// The expression removes the comma from the price string and converts it into a number. This allows JavaScript to use the value in calculations.
0 commit comments