Skip to content

Commit 8161a89

Browse files
committed
Answered the questions in 2.js and fixed the code required.
1 parent a0786f8 commit 8161a89

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
@@ -1,20 +1,28 @@
11

22
// Predict and explain first BEFORE you run any code...
33

4-
// this function should square any number but instead we're going to get an error
4+
// the function square(3) wont work as you cant have a number value for the function.
55

66
// =============> write your prediction of the error here
7+
// return num * num; wont work as
78

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

1213
// =============> write the error message here
14+
// SyntaxError: Unexpected number
1315

1416
// =============> explain this error message here
17+
// in the () is the parameter for the function and that cannot be a number as it has to be a name, following the same rules
18+
// that are used so it can't start with a number.
1519

1620
// Finally, correct the code to fix the problem
1721

1822
// =============> write your new code here
23+
function square(num) {
24+
return num * num;
25+
}
1926

2027

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

0 commit comments

Comments
 (0)