Skip to content

Commit b857592

Browse files
committed
Fix parameter definition in square function and update error predictions and explanations
1 parent 8d94e35 commit b857592

File tree

1 file changed

+18
-1
lines changed
  • Sprint-2/1-key-errors

1 file changed

+18
-1
lines changed

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,37 @@
11

22
// Predict and explain first BEFORE you run any code...
33

4+
// I predict that the code will throw a ReferenceError because the variable 'num' is not defined within the function scope.
5+
46
// this function should square any number but instead we're going to get an error
57

8+
//
9+
610
// =============> write your prediction of the error here
711

12+
// I predict that the code will throw a ReferenceError because the variable 'num' is not defined within the function scope.
13+
14+
/
15+
816
function square(3) {
917
return num * num;
1018
}
1119

1220
// =============> write the error message here
1321

22+
// ReferenceError: num is not defined
23+
1424
// =============> explain this error message here
1525

26+
// This error message indicates that the variable 'num' is being used before it has been declared or defined.
27+
// In the function 'square', the parameter is incorrectly defined as a literal value (3) instead of a variable name.
28+
1629
// Finally, correct the code to fix the problem
1730

1831
// =============> write your new code here
1932

20-
33+
function square(num) {
34+
return num * num;
35+
}
36+
// Example:
37+
console.log(square(3)); // Output: 9

0 commit comments

Comments
 (0)