File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change 44// this function should square any number but instead we're going to get an error
55
66// =============> write your prediction of the error here
7+ // This code will throw a SyntaxError because function parameters must be valid variable names,
8+ // not literal values like 3.
79
10+ /**
811function square(3) {
912 return num * num;
1013}
14+ */
1115
1216// =============> write the error message here
17+ // SyntaxError: Unexpected number
18+ // (or "SyntaxError: Unexpected token '3'" depending on the environment)
1319
1420// =============> explain this error message here
15-
21+ // The error occurs because JavaScript expects a variable name (like num or x) inside the parentheses
22+ // of a function definition. You cannot use a number (3) as a parameter name — it’s not a valid identifier.
23+ // Function parameters act as variable placeholders for input values, so they must follow variable naming rules.
24+ //
1625// Finally, correct the code to fix the problem
1726
1827// =============> write your new code here
1928
29+ function square ( num ) {
30+ return num * num ;
31+ }
32+
33+ console . log ( square ( 3 ) ) ; // Output: 9
2034
You can’t perform that action at this time.
0 commit comments