Skip to content

Commit 3dcaa8f

Browse files
committed
Fix syntax error in square function by using a variable as parameter
1 parent fd7a6c5 commit 3dcaa8f

File tree

1 file changed

+17
-3
lines changed
  • Sprint-2/1-key-errors

1 file changed

+17
-3
lines changed

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,31 @@
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+
// in javaScript function parameters should be variable names, but in line 10 we used a number "3" as parameter,
8+
// so the error will be "SyntaxError"
79

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

1214
// =============> write the error message here
15+
// function square(3) {
16+
// ^
17+
18+
// SyntaxError: Unexpected number
1319

1420
// =============> explain this error message here
1521

22+
// the problem is in line 10, because we can not use a number as parameter of the function, it should be variable name,
23+
// so the error is "SyntaxError: Unexpected number"
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+
2033

34+
console.log(square(3));

0 commit comments

Comments
 (0)