Skip to content

Commit c14ac01

Browse files
committed
evaluated the code and explained errors in 2.js file
1 parent 7dfe904 commit c14ac01

File tree

1 file changed

+14
-6
lines changed
  • Sprint-2/1-key-errors

1 file changed

+14
-6
lines changed

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
11

22
// Predict and explain first BEFORE you run any code...
3-
43
// this function should square any number but instead we're going to get an error
4+
//
55

66
// =============> write your prediction of the error here
7-
8-
function square(3) {
9-
return num * num;
10-
}
7+
// // This code would throw a syntaxerror "missing valid function parameter".
8+
// function square(3) {
9+
// return num * num;
10+
// }
1111

1212
// =============> write the error message here
13+
// function square(3) {
14+
// ^
1315

16+
// SyntaxError: Unexpected number
1417
// =============> explain this error message here
18+
// The JavaScript exception "missing formal parameter" occurs when your function declaration is missing valid parameters.
19+
// In the declaration of a function, the parameters must be identifiers, not any value like numbers, strings, or objects.
1520

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

1823
// =============> write your new code here
1924

20-
25+
function square(num) {
26+
return num * num;
27+
}
28+
console.log(square(10));

0 commit comments

Comments
 (0)