Skip to content

Commit 701d553

Browse files
committed
Fix syntax error in square function by updating parameter name
1 parent a8976b0 commit 701d553

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

  • Sprint-3/1-key-errors

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,24 @@
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+
// I predict that there will be a syntax error because the parameter name "3" is not a valid
8+
// identifier.
79

810
function square(3) {
911
return num * num;
1012
}
1113

1214
// =============> write the error message here
15+
// SyntaxError: Function argument name must be a valid identifier
1316

1417
// =============> explain this error message here
18+
// The error occurs because "3" is not a valid identifier for a function parameter.
19+
// In JavaScript, parameter names must follow the rules for identifiers, which means they
20+
// cannot be numbers or reserved keywords.
1521

1622
// Finally, correct the code to fix the problem
1723

1824
// =============> write your new code here
19-
20-
25+
function square(num) {
26+
return num * num;
27+
}

0 commit comments

Comments
 (0)