File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1-
21// Predict and explain first BEFORE you run any code...
3-
42// this function should square any number but instead we're going to get an error
5-
63// =============> write your prediction of the error here
4+ // Prediction: SyntaxError — you cannot use a number literal (3) as a parameter name.
5+ // Parameter names must be valid identifiers (e.g. num), not values.
6+ // The value 3 should be passed when calling the function, not in the definition.
77
8- function square ( 3 ) {
9- return num * num ;
10- }
8+ // function square(3) {
9+ // return num * num;
10+ // }
1111
1212// =============> write the error message here
13+ // SyntaxError: Unexpected number
14+ // (exact wording can vary slightly by Node version, e.g. "Missing formal parameter")
1315
1416// =============> explain this error message here
17+ // In a function definition, the parentheses list parameter names (placeholders).
18+ // 3 is a value (argument), not a name, so JavaScript rejects it while parsing the file.
19+ // Even if that were fixed, num is not defined in the original code — the parameter
20+ // and the name used inside the function must match.
1521
1622// Finally, correct the code to fix the problem
17-
1823// =============> write your new code here
24+ function square ( num ) {
25+ return num * num ;
26+ }
1927
28+ console . log ( square ( 3 ) ) ;
2029
You can’t perform that action at this time.
0 commit comments