Skip to content

Commit cd6e897

Browse files
committed
Predicted, explained and fixed code errors
1 parent ac1886b commit cd6e897

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

  • Sprint-3/1-key-errors

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,25 @@
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+
// Error because 3 is a value, functions take parameters(like num).
8+
// It wont work 3 is a number literal and not a name/identifier.
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+
// SyntaxError: Unexpected number
1316

1417
// =============> explain this error message here
18+
// The code was expecting the parameter name but found the number literal =3
19+
// This is why we get the syntax error.
1520

1621
// Finally, correct the code to fix the problem
1722

1823
// =============> write your new code here
24+
function square(num) {
25+
return num * num;
26+
}
1927

20-
28+
console.log(square(3));

0 commit comments

Comments
 (0)