Skip to content

Commit 500a0f6

Browse files
committed
Fix square function error
1 parent 775070d commit 500a0f6

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

  • Sprint-3/1-key-errors

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
1-
21
// Predict and explain first BEFORE you run any code...
32

43
// this function should square any number but instead we're going to get an error
54

5+
// Prediction: I predict that an error will occur because 3 cannot
6+
// be used as a function parameter name.
7+
68
// =============> write your prediction of the error here
79

8-
function square(3) {
10+
function square(num) {
11+
912
return num * num;
13+
1014
}
1115

1216
// =============> write the error message here
1317

18+
// SyntaxError: Unexpected number
19+
1420
// =============> explain this error message here
1521

22+
// The error happens because 3 is a number, not a valid parameter name.
23+
// A function parameter needs to be a variable name, such as num.
24+
1625
// Finally, correct the code to fix the problem
1726

1827
// =============> write your new code here
1928

20-
29+
console.log(square(3));

0 commit comments

Comments
 (0)