Skip to content

Commit 40825f8

Browse files
committed
Added MDN-based explanation,and documented variable declarations
1 parent 6ea69f1 commit 40825f8

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,25 @@ 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+
// 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+
1620
// 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?
1721

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+
1824
// c) Identify all the lines that are variable reassignment statements
25+
// Line 4: Reassignment (not a declaration)
26+
// Line 5: Reassignment (not a declaration)
1927

2028
// 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'
2133

2234
// 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

Comments
 (0)