Skip to content

Commit 324b237

Browse files
committed
add answers to the questions
1 parent c267bf0 commit 324b237

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;
@@ -12,11 +12,27 @@ 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 5 function calls. carPrice = Number(carPrice.replaceAll(",", ""));
16+
// priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));
17+
// In the above 2 lines, 2 replaceAll() functions for carPrice and priceAfterOneyear and after executing them again Number()
18+
// functions for the 2 variables.
19+
// At last, console.log() function for printing the executed value.
1520

1621
// 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?
22+
// after running the code, the error is coming from this line priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));and
23+
// the error is SyntaxError: missing ) after argument list. There is a comma missing in replaceAll() syntax. It should be
24+
// priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));
1725

1826
// c) Identify all the lines that are variable reassignment statements
27+
// There are 2 variable reassignment statements.
28+
// const priceDifference = carPrice - priceAfterOneYear;
29+
// const percentageChange = (priceDifference / carPrice) * 100;
1930

2031
// d) Identify all the lines that are variable declarations
32+
// There are 4 variable declarations lines.
33+
// let carPrice = "10,000";
34+
// let priceAfterOneYear = "8,543";
2135

2236
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
37+
// Firstly this expression replace all the commas from the variable carPrice = "10,000" to "10000" and then it converts
38+
// string "10,000" to number 10000.

0 commit comments

Comments
 (0)