Skip to content

Commit 468f39f

Browse files
Fix 2.js: use a parameter name instead of a number
1 parent 01b0572 commit 468f39f

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 a SyntaxError, because 3 is a number, not a parameter name.
8+
// Function parameters must be identifiers (variable names).
79

8-
function square(3) {
10+
function square(num) {
911
return num * num;
1012
}
1113

1214
// =============> write the error message here
15+
// SyntaxError: Unexpected number
1316

1417
// =============> explain this error message here
18+
// The original code was function square(3) { ... }. A function definition
19+
// expects a parameter name inside the brackets, but I gave it the value 3.
20+
// JavaScript found a number where it expected a name, so it says
21+
// "Unexpected number".
1522

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

1825
// =============> write your new code here
19-
26+
console.log(square(3));
2027

0 commit comments

Comments
 (0)