Skip to content

Commit bdd3224

Browse files
committed
fix: update the number of function calls and improve readability in the explanation of lines 4 and 5the lines 4 and 5.
1 parent e47833b commit bdd3224

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

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

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,10 @@ 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-
// There are 6 function calls in this file:
17-
// Line 5: carPrice.replaceAll(",", "")
18-
// Line 5: Number(carPrice.replaceAll(",", ""))
19-
// Line 6: priceAfterOneYear.replaceAll(",", "")
20-
// Line 6: Number(priceAfterOneYear.replaceAll(",", ""))
21-
// Line 10: console.log(`The percentage change is ${percentageChange}`) this is also
22-
// a function call to log the output as string to the console, then call the var percentageChange
16+
// There are 5 function calls in this file:
17+
// Line 4: Number() and replaceAll(",", "")
18+
// Line 5: Number() and replaceAll(",", "")
19+
// Line 10: console.log()
2320

2421

2522
// 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?
@@ -37,12 +34,12 @@ console.log(`The percentage change is ${percentageChange}`);
3734

3835
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
3936

40-
// This expression will work in the parenthesis first, replacing all commas in the string carPrice
41-
// with an empty string, so basically returning the string 10000 instead of "10,000".
42-
// Then the Number() function will convert that string "10000" into a number 10000.
43-
// secondly, js can not treat strings with commas as numbers, so we need to remove the commas
44-
// now with the number cleaned we can convert this string in number with the method Number().
37+
// First, replaceAll(",", "") removes the commas from the string because JavaScript
38+
// cannot perform math on strings containing symbols. It turns "10,000" into "10000".
4539

40+
// Then, the Number() function converts that clean string into an actual number.
41+
// The purpose is to prepare the data for calculation; without this, JavaScript
42+
// would return NaN (Not a Number) when trying to subtract the prices.
4643

4744

4845
// ---------- console.log each step to see the results ----------

0 commit comments

Comments
 (0)