Skip to content

Commit ce151be

Browse files
committed
submitted completed task
1 parent 4b403bd commit ce151be

File tree

1 file changed

+12
-7
lines changed
  • Sprint-2/1-key-errors

1 file changed

+12
-7
lines changed

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

Lines changed: 12 additions & 7 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
7-
6+
/*
87
function square(3) {
98
return num * num;
109
}
11-
10+
*/
1211
// =============> write the error message here
13-
12+
// 1-SyntaxError: Unexpected number.
1413
// =============> explain this error message here
15-
14+
/*
15+
1-The parameter name '3' is not a valid identifier. Function parameters names must (be valid variable names & not literal values), i.e. start with a letter, underscore (_), or dollar sign ($), and cannot be a number.
16+
2-Also, the function uses 'num' which is not defined anywhere. It should use the parameter name instead.
17+
3-Finally, the function is not called anywhere, so it won't produce any output.
18+
*/
1619
// Finally, correct the code to fix the problem
1720

1821
// =============> write your new code here
19-
20-
22+
function square(num) {
23+
return num * num;
24+
}
25+
console.log(square(3)); // This line is inserted only to test the function. It returns 9

0 commit comments

Comments
 (0)