Skip to content

Commit 7555838

Browse files
error fixed
1 parent dd98827 commit 7555838

File tree

1 file changed

+9
-5
lines changed
  • Sprint-2/1-key-errors

1 file changed

+9
-5
lines changed

Sprint-2/1-key-errors/2.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@
1212
// Additionally, num is used inside the function without being declared or passed as an argument, which causes a ReferenceError.
1313
// If the function is not called, it will not execute.
1414

15-
function square(num) {
15+
function square(3) {
1616
return num * num;
1717
}
18-
let num = square(3);
19-
console.log(num);
18+
2019

2120

2221
// =============> write the error message here
@@ -30,11 +29,16 @@ console.log(num);
3029
// Also, if the function is not called, it will not execute.
3130

3231
// Finally, correct the code to fix the problem
32+
// I corrected the function by properly defining num as a parameter instead of using a number in the function definition. This resolved the syntax error.
33+
34+
// Inside the function, num is now defined, so the ReferenceError is fixed.
3335

36+
// I then called the function with an argument and stored the returned value in a variable named num. Although the same variable name is used, the function parameter and the outer variable exist in different scopes, so there is no conflict.
3437
// =============> write your new code here
3538

39+
3640
function square(num) {
3741
return num * num;
3842
}
39-
40-
console.log(square(3));
43+
let num = square(3);
44+
console.log(num);

0 commit comments

Comments
 (0)