Skip to content

Commit a613e4c

Browse files
author
russom
committed
Answer question. Fix code. Add comma.
1 parent 209739c commit a613e4c

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

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

Lines changed: 14 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,16 @@ 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+
// Answers
25+
26+
// a) There are no function or function calls in this code.
27+
28+
// b) The error was online 5 inside replaceAll method parentheses a comma is missing between the double quotes.
29+
30+
// c) Line 4 carPrice. Line 5 priceAfterOneYear.
31+
32+
// d) Line 1, 2, 7 and 8.
33+
34+
// e) The method replaceALL is removing the comma. Then the Number method is converting the string into numbers.
35+
// The purpose is to use number operations and calculate the percentage change.

0 commit comments

Comments
 (0)