File tree Expand file tree Collapse file tree 1 file changed +13
-0
lines changed
Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change 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
811function 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
You can’t perform that action at this time.
0 commit comments