Skip to content

Commit d8e5852

Browse files
committed
answered all questions in 1-percentage-change.js
1 parent df2d214 commit d8e5852

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

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

Lines changed: 9 additions & 2 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;
@@ -12,11 +12,18 @@ console.log(`The percentage change is ${percentageChange}`);
1212
// Read the code and then answer the questions below
1313

1414
// a) How many function calls are there in this file? Write down all the lines where a function call is made
15+
// There are 3 function calls. line 4 Number() and .replaceAll()
16+
// line 12 console,log()
1517

1618
// 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?
19+
//A syntaxError is occurring on line 5, we are missing a "," and a closing ")"
1720

1821
// c) Identify all the lines that are variable reassignment statements
22+
// line 4 and 5
1923

2024
// d) Identify all the lines that are variable declarations
21-
25+
// line 1, 2, 7, 8
2226
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
27+
/* We are removing the comma, the replaceAll method takes in two arguements, 1 for what to replace and 2 for what to
28+
replace by, and in this case we are replaceing the comma with an empty string. we wrap the carPrice variable which is a string
29+
with the Number() function to convert it into a number*/

0 commit comments

Comments
 (0)