Skip to content

Commit 455e47f

Browse files
committed
replace numeric parameter 3 with valid name num
1 parent 5547d83 commit 455e47f

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

  • Sprint-2/1-key-errors

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

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,28 @@
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 I will get a SyntaxError as a parameter cannot
8+
// be a Number, parameters must be valid variable names.
79

8-
function square(3) {
9-
return num * num;
10-
}
10+
// function square(3) {
11+
// return num * num;
12+
// }
1113

12-
// =============> write the error message here
14+
// =============> write the error message here:
15+
// SyntaxError: Unexpected number
1316

1417
// =============> explain this error message here
18+
// Function parameters must be valid variable names, they must
19+
// follow the same naming rules. a number like 3 is not a valid
20+
// parameter name.
21+
// TO fix the code, rename the parameter to num (or any valid variable
22+
// name) and use it in the return statement.)
1523

1624
// Finally, correct the code to fix the problem
1725

1826
// =============> write your new code here
27+
function square(num) {
28+
return num * num;
29+
}
1930

20-
31+
console.log(square(3)); // This should now work and output 9

0 commit comments

Comments
 (0)