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
@@ -13,17 +13,17 @@ console.log(`The percentage change is ${percentageChange}`);
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
15
16
-
// 1. carPrice.replaceAll(",", "")
17
-
// 2. priceAfterOneYear.replaceAll(",", "")
18
-
// 3. Number(...)
19
-
// 4. console.log(...) -
16
+
// 1. carPrice.replaceAll(",", "")
17
+
// 2. priceAfterOneYear.replaceAll(",", "")
18
+
// 3. Number(...)
19
+
// 4. console.log(...) -
20
20
// 5. (priceDifference / carPrice) * 100 - line 7 (this is an expression that involves division and multiplication, but it does not involve a function call)
21
21
22
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
23
24
-
// The error is on line 5 where `priceAfterOneYear.replaceAll(",", "")` is called. The syntax error is due to a missing closing quote in the `replaceAll` method.
25
-
// Fix: Change `priceAfterOneYear.replaceAll(",", "")` to `priceAfterOneYear.replaceAll(",", "")`
26
-
24
+
//// The error is on line 5 where `priceAfterOneYear.replaceAll("," "")` is called.
25
+
// The syntax error occurs because there is a missing comma between the arguments in the `replaceAll` method.
26
+
// Fix: Change `priceAfterOneYear.replaceAll("," "")` to `priceAfterOneYear.replaceAll(",", "")`
27
27
// c) Identify all the lines that are variable reassignment statements
28
28
29
29
// Line 4: carPrice = Number(carPrice.replaceAll(",", ""));
@@ -37,4 +37,4 @@ console.log(`The percentage change is ${percentageChange}`);
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
40
-
// The expression `carPrice.replaceAll(",", "")` removes all commas from the string `carPrice`, converting it to a number that can be used in mathematical operations. This is necessary because the original value is a string with commas (e.g., "10,000"), which cannot be directly used in arithmetic calculations. The `Number()` function then converts the resulting string (e.g., "10000") into a numeric value.
40
+
// The expression `carPrice.replaceAll(",", "")` removes all commas from the string `carPrice`, converting it to a number that can be used in mathematical operations. This is necessary because the original value is a string with commas (e.g., "10,000"), which cannot be directly used in arithmetic calculations. The `Number()` function then converts the resulting string (e.g., "10000") into a numeric value.
0 commit comments