Skip to content

Commit d311b62

Browse files
committed
Predict and explain error. Fix by giving adding variable name to parameter and giving default value
1 parent b862d6d commit d311b62

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

  • Sprint-3/1-key-errors

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
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+
// In the function, 3 hasn't been assigned to num, so num is NaN and should return NaN.
7+
//Also when defining a function, the parameter should have the variable name, not a value
8+
//to pass in, unless you want to default value such as num = 3, which assigns 3 to num if
9+
// no value is passed in
710

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

1215
// =============> write the error message here
13-
16+
//SyntaxError: Unexpected number
1417
// =============> explain this error message here
15-
18+
//syntaxError means there is a mistake in the way the code is written, so javascript can't
19+
// interpret the code. in this case there is a number here when there shouldn't be.
1620
// Finally, correct the code to fix the problem
1721

1822
// =============> write your new code here
1923

20-
24+
function square(num = 3) {
25+
return num * num;
26+
}

0 commit comments

Comments
 (0)