Skip to content

Commit 722ed1c

Browse files
committed
Add detailed explanation for Number conversion in 1-percentage-change.js
1 parent 0a35180 commit 722ed1c

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,10 @@ console.log(`The percentage change is ${percentageChange}`);
4343
// Line 1: let carPrice = "10,000";
4444
// Line 2: let priceAfterOneYear = "8,543";
4545
// Line 7: const priceDifference = carPrice - priceAfterOneYear;
46-
// Line 8: const percentageChange = (priceDifference / carPrice) * 100;
46+
// Line 8: const percentageChange = (priceDifference / carPrice) * 100;
47+
48+
// e) Number(carPrice.replaceAll(",","")) is two steps combined, whereby:
49+
// carPrice.replaceAll(",","") takes the string "10,000" and deletes every comma, making it 10000
50+
// and Number() converts the new string into an actual numeric value
51+
// The purpose of the expression is to strip out the formatting comma first from the string
52+
// so that JavaScript does not treat it as plain text, and then converts the result into real numbers for it to be used in math, similar to Line 7

0 commit comments

Comments
 (0)