Skip to content

Commit dd95e03

Browse files
authored
Reading the code and answering the questions
1 parent 72a2ea2 commit dd95e03

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,46 @@ console.log(`The percentage change is ${percentageChange}`);
1313

1414
// a) How many function calls are there in this file? Write down all the lines where a function call is made
1515

16+
// There are 5 function calls in this file:
17+
// line 4: carPrice.replaceAll(",", "")
18+
// line 4: Number(carPrice.replaceAll(",", ""))
19+
//line 5: priceAfterOneYear.replaceAll("," "")
20+
// line 5: Number(priceAfterOneYear.replaceAll("," ""))
21+
// line 9: console.log(`The percentage change is ${percentageChange}`)
22+
23+
24+
1625
// 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?
26+
/*
27+
It's a SyntaxError in line 5: priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));.
28+
The error is occurring because there is a missing comma between the two arguments of the replaceAll function here ("," "").
29+
To fix this problem, we need to add a comma between the two arguments: replaceAll(",", "").
30+
*/
31+
32+
1733

1834
// c) Identify all the lines that are variable reassignment statements
35+
/*reusing the same variable carPrice but updating its value:
36+
carPrice = Number(carPrice.replaceAll(",", ""));
37+
38+
reusing the same variable priceAfterOneYear but updating its value:
39+
priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));
40+
*/
41+
42+
1943

2044
// d) Identify all the lines that are variable declarations
45+
/*declaring a new variable carPrice:
46+
let carPrice = "10,000";
47+
48+
declaring a new variable priceAfterOneYear:
49+
let priceAfterOneYear = "8,543";
50+
*/
51+
52+
2153

2254
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
55+
/*
56+
The expression Number(carPrice.replaceAll(",", "")) is converting the carPrice string into a number.
57+
The purpose of this expression is to get a numeric value for carPrice that can be used for calculations.
58+
*/

0 commit comments

Comments
 (0)