Skip to content

Commit 51551e1

Browse files
sovling exercise 1-percentage-change
1 parent 8fc0ed8 commit 51551e1

1 file changed

Lines changed: 45 additions & 2 deletions

File tree

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

Lines changed: 45 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;
@@ -13,10 +13,53 @@ 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-
// 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?
1716

17+
/*
18+
Solution to a)
19+
-------------|-----------------| --------
20+
1 | Number() | line 4 |
21+
2 | replaceAll() | line 4 |
22+
3 | Number() | line 5 |
23+
4 | replaceAll() | line 5 |
24+
5 | console.log() | line 10 |
25+
------------------------------------------
26+
27+
28+
*/
29+
30+
31+
// 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?
32+
/*
33+
Solution to b)
34+
After running the code the terminal gives SyntaxError: missing ) after argument list BUT the actual error is not having a comma in line 5 in the replaceAll methode as it needs two arguments
35+
eplaceAll("," "") => should be eplaceAll("," , "")
36+
*/
1837
// c) Identify all the lines that are variable reassignment statements
38+
/*
39+
Solution to c)
40+
Variable reassignment statements lines are:
41+
42+
line 4 : carPrice = Number(carPrice.replaceAll(",", ""));
43+
line 5 : priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));
44+
*/
1945

2046
// d) Identify all the lines that are variable declarations
47+
/*
48+
Solution to d)
49+
Variable declarations lines are:
50+
line 1 :let carPrice = "10,000";
51+
line 2 :let priceAfterOneYear = "8,543";
52+
line 7 :const priceDifference = carPrice - priceAfterOneYear;
53+
c line 8 :const percentageChange = (priceDifference / carPrice) * 100;
54+
55+
*/
2156

2257
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
58+
59+
/*
60+
Solution to e)
61+
The expresssion Number(carPrice.replaceAll(",","")) is removing the comma "," in CarPrice i.e from 10,000 to 10000 which is stored
62+
in String type , removing the comma will insure the mathimatical operation will go normal when converted to type Number.
63+
64+
*/
65+

0 commit comments

Comments
 (0)