Skip to content

Commit 508504c

Browse files
committed
correct square function parameter
1 parent 68d57ce commit 508504c

File tree

1 file changed

+13
-4
lines changed
  • Sprint-2/1-key-errors

1 file changed

+13
-4
lines changed

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
11

22
// Predict and explain first BEFORE you run any code...
3+
// Function parameters must be variables, not numbers.
34

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

67
// =============> write your prediction of the error here
8+
// The code will give a SyntaxError because `3` is not a valid parameter name.
79

8-
function square(3) {
9-
return num * num;
10-
}
10+
//function square(3) {
11+
// return num * num;
12+
// }
1113

1214
// =============> write the error message here
15+
// SyntaxError: Unexpected number
1316

1417
// =============> explain this error message here
15-
18+
// The error happens because `3` is used as a parameter name.
19+
// Parameters must be variable names, not numbers.
1620
// Finally, correct the code to fix the problem
1721

1822
// =============> write your new code here
1923

24+
function square(number) {
25+
return number * number;
26+
}
27+
console.log(square(3));
28+
2029

0 commit comments

Comments
 (0)