Skip to content

Commit a52cfdb

Browse files
answer questions
1 parent 01adbcc commit a52cfdb

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;
@@ -12,11 +12,24 @@ 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+
/* Number() - line 4 and Line 5
16+
replaceAll() - Line 4 and Line 5
17+
console.log() - Line 10*/
18+
1519

1620
// 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?
21+
/* line 5 , There is a comma missing between "," and ""*/
1722

1823
// c) Identify all the lines that are variable reassignment statements
24+
/* Line 4 :carPrice = Number(carPrice.replaceAll(",", ""));
25+
Line5 : priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));
26+
carPrice and priceAfterOneYear were already declared on Line 1 and 2 using let */
1927

2028
// d) Identify all the lines that are variable declarations
29+
/* Line 1 : let carPrice = "10,000";
30+
Line 2 : let priceAfterOneYear = "8,543";
31+
Line 7 : const priceDifference = carPrice - priceAfterOneYear;
32+
Line 8 : const percentageChange = (priceDifference / carPrice) * 100;*/
2133

2234
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
35+
/*replaceAll remove all the commas from the string and Number convert string to the number*/

0 commit comments

Comments
 (0)