Skip to content

Commit c278bbb

Browse files
committed
Use valid parameter name instead of number in square function
1 parent fcba7aa commit c278bbb

File tree

1 file changed

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

1 file changed

+13
-0
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,32 @@
22
// Predict and explain first BEFORE you run any code...
33

44
// this function should square any number but instead we're going to get an error
5+
// The code will throw a **SyntaxError** because you cannot
6+
// use a number (`3`) as a function parameter name.
57

68
// =============> write your prediction of the error here
9+
// SyntaxError: Unexpected number
710

811
function square(3) {
912
return num * num;
1013
}
1114

1215
// =============> write the error message here
16+
// SyntaxError: Unexpected number
1317

1418
// =============> explain this error message here
19+
// In JavaScript, function parameters must be valid variable names (identifiers).
20+
// Using a number like `3` directly as a parameter name is invalid syntax,
21+
// so JavaScript throws a `SyntaxError: Unexpected number`.
1522

1623
// Finally, correct the code to fix the problem
1724

1825
// =============> write your new code here
1926

27+
function square(num) {
28+
return num * num;
29+
}
30+
31+
console.log(square(3));
32+
2033

0 commit comments

Comments
 (0)