Skip to content

Commit a983056

Browse files
author
Pretty Taruvinga
committed
fix syntax error explanation
1 parent 4060f63 commit a983056

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

Sprint-1/3-mandatory-interpret/1-percentage-change.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ let carPrice = "10,000";
22
let priceAfterOneYear = "8,543";
33

44
carPrice = Number(carPrice.replaceAll(",", ""));
5-
priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));
5+
priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));
66

77
const priceDifference = carPrice - priceAfterOneYear;
88
const percentageChange = (priceDifference / carPrice) * 100;
@@ -13,17 +13,17 @@ console.log(`The percentage change is ${percentageChange}`);
1313

1414
// a) How many function calls are there in this file? Write down all the lines where a function call is made
1515

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(...) -
2020
// 5. (priceDifference / carPrice) * 100 - line 7 (this is an expression that involves division and multiplication, but it does not involve a function call)
2121

2222
// 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?
2323

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(",", "")`
2727
// c) Identify all the lines that are variable reassignment statements
2828

2929
// Line 4: carPrice = Number(carPrice.replaceAll(",", ""));
@@ -37,4 +37,4 @@ console.log(`The percentage change is ${percentageChange}`);
3737
// Line 8: const percentageChange = (priceDifference / carPrice) * 100;
3838

3939
// 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

Comments
 (0)