Skip to content

Commit 9a730bc

Browse files
author
russom
committed
Questions answered and errors fixed.
1 parent 56fa843 commit 9a730bc

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

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

Lines changed: 17 additions & 1 deletion
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;
@@ -20,3 +20,19 @@ console.log(`The percentage change is ${percentageChange}`);
2020
// d) Identify all the lines that are variable declarations
2121

2222
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
23+
24+
// Answer
25+
// a) Line 4: Number(carPrice.replaceAll(",", "")); and carPrice.replaceAll(",", "")
26+
// a) Line 5: Number(priceAfterOneYear.replaceAll("," "")); and priceAfterOneYear.replaceAll("," "")
27+
28+
// b) The error is coming from line 5. The error is occurring in the replaceAll method a comma is missing between ("," "") it should be (",", "") to fix the problem.
29+
30+
// c) line 4: carPrice = Number(carPrice.replaceAll(",", ""));
31+
// c) line 5: priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));
32+
33+
// d) Line 1: let carPrice = "10,000";
34+
// d) Line 2: let priceAfterOneYear = "8,543";
35+
// d) Line 7: const priceDifference = carPrice - priceAfterOneYear;
36+
// d) Line 8: const percentageChange = (priceDifference / carPrice) * 100;
37+
38+
// e) Number() is converting the string into a number. replaceAll() is removing the comma from the string.

0 commit comments

Comments
 (0)