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
Copy file name to clipboardExpand all lines: Sprint-1/3-mandatory-interpret/1-percentage-change.js
+15Lines changed: 15 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -13,10 +13,25 @@ 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
+
// Line 4 contains two function calls: replaceAll(",", "") & Number(...)
17
+
// Line 5 also contains two function calls: replaceAll(",","") & Number(...)
18
+
// Line 10 contains one function call: console.log()
19
+
16
20
// 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
21
22
+
// The error originates from line 5: SyntaxError: missing ) after argument list. According to MDN Web Docs, this occurs when there is a problem with how a function is called - typically caused by a typo, a missing separator (such as a comma), or an incorrectly formatted string within the argument list
23
+
18
24
// c) Identify all the lines that are variable reassignment statements
25
+
// Line 4: Reassignment (not a declaration)
26
+
// Line 5: Reassignment (not a declaration)
19
27
20
28
// d) Identify all the lines that are variable declarations
29
+
// Line 1: Variable declaration using 'let'
30
+
// Line 2: Variable declaration using 'let'
31
+
// Line 7: Variable declaration using 'const'
32
+
// Line 8: Variable declaration using 'const'
21
33
22
34
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
35
+
/* The expression Number(carPrice.replaceAll(",","")) first uses the String.prototype.replaceAll() method to remove all commas from the string stored in carPrice
36
+
It then passes the resulting string to the Number() function, which converts it into a numeric value. According to MDN, replaceALL() returns a new string with all occurrences of a
37
+
specified substring replaced, and Number() converts its argument to a number or return NaN if the conversion fails */
0 commit comments