Skip to content

Commit ea085d9

Browse files
committed
Solved task 1-key-errors/2.js
1 parent 83a2f87 commit ea085d9

File tree

1 file changed

+10
-5
lines changed
  • Sprint-2/1-key-errors

1 file changed

+10
-5
lines changed

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
1-
21
// Predict and explain first BEFORE you run any code...
32

43
// this function should square any number but instead we're going to get an error
54

65
// =============> write your prediction of the error here
6+
//I think that's an error because there is no declared variable "num".
77

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

1212
// =============> write the error message here
13+
// SyntaxError: Unexpected number
1314

1415
// =============> explain this error message here
16+
// As I can see now after running the code, I missed the very first error - we can't use a number as a parameter name, and JavaScript even didn't go after the very first mistake to check others errors (and my predicted error about undeclared "num")
1517

1618
// Finally, correct the code to fix the problem
1719

1820
// =============> write your new code here
21+
function square(num) {
22+
return num * num;
23+
}
1924

20-
25+
console.log(square(12)); // 144

0 commit comments

Comments
 (0)