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,26 @@ 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 this file: lines 3, 4 and 7
16
+
// Line 4: carPrice,replaceAll(",", "") removes all commas from string
17
+
// Line 4: Number(...) converts string into number
18
+
// Line 5: priceAfterOneYear.replaceAll("," "") removes all commas from string
19
+
// Line 5: Number(...) converts string to number
20
+
// Line 10: console.log(`The percentage change is ${percentageChange}`) prints percentage change to output
15
21
16
22
// 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
+
// Line 5 is missing a comma in the replaceAll function call. This is causing a syntax error because the function expects two arguments, but only one is provided.
17
24
18
25
// c) Identify all the lines that are variable reassignment statements
26
+
// Variable reassignment means giving an existing variable a new value.
27
+
// Lines 4 and 5 reassign new values to carPrice and priceAfterOneYear respectively.
19
28
20
29
// d) Identify all the lines that are variable declarations
30
+
// Variable declaration means creating a new variable and assigning it a value for the first time.
31
+
// Line 1 declares carPrice with let
32
+
// Line 2 declares priceAfterOneYear with let
33
+
// Line 7 declares priceDifference with const
34
+
// Line 8 declares percentageChange with const
21
35
22
36
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
37
+
// It converts the string value of carPrice into a number value and removes the comma.
0 commit comments