You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -13,10 +13,53 @@ console.log(`The percentage change is ${percentageChange}`);
13
13
14
14
// a) How many function calls are there in this file? Write down all the lines where a function call is made
15
15
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?
17
16
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
+
*/
18
37
// 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
+
*/
19
45
20
46
// 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
+
*/
21
56
22
57
// 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.
0 commit comments