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-2/1-key-errors/1.js
+8-9Lines changed: 8 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -6,19 +6,11 @@
6
6
/**
7
7
* Prediction:
8
8
* An error will occur because the function parameter decimalNumber is being redeclared inside the function body using const. This creates a naming conflict - you can't have a parameter and a local variable with the same name.
9
-
* Additionally, the console.log(decimalNumber) at the end will cause a ReferenceError because decimalNumber is not defined in the global scope - it's only defined within the function's scope.
9
+
* Additionally, the console.log(decimalNumber) at the end will cause a ReferenceError because decimalNumber is not defined in the global scope, it's only defined within the function's scope.
10
10
*/
11
11
12
12
// Try playing computer with the example to work out what is going on
13
13
14
-
/**
15
-
* Explanation
16
-
* The code has two main problems:
17
-
* Redeclaration error: The function parameter decimalNumber is being redeclared with const decimalNumber = 0.5 inside the function. In JavaScript, you cannot have a variable with the same name as a parameter in the same scope.
18
-
* Scope error: The console.log(decimalNumber) at the end is trying to access a variable that only exists inside the function's scope. Variables declared inside functions are not accessible from the outside.
19
-
* Logic error: Even if the scope issues were fixed, the function always returns "50%" regardless of the input because it overwrites the parameter with 0.5.
20
-
*/
21
-
22
14
/** Original function:
23
15
*
24
16
* function convertToPercentage(decimalNumber) {
@@ -32,6 +24,13 @@
32
24
*/
33
25
34
26
// =============> write your explanation here
27
+
/**
28
+
* Explanation
29
+
* The code has two main problems:
30
+
* Redeclaration error: The function parameter decimalNumber is being redeclared with const decimalNumber = 0.5 inside the function. In JavaScript, it not possible to have a variable with the same name as a parameter in the same scope.
31
+
* Scope error: The console.log(decimalNumber) at the end is trying to access a variable that only exists inside the function's scope. Variables declared inside functions are not accessible from the outside.
32
+
* Logic error: Even if the scope issues were fixed, the function always returns "50%" regardless of the input because it overwrites the parameter with 0.5.
0 commit comments