Skip to content

Commit 02c8367

Browse files
authored
Fix square function parameter and return statement
Corrected the square function to use a valid parameter name and return the square of the input.
1 parent 1eea298 commit 02c8367

File tree

1 file changed

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

1 file changed

+19
-7
lines changed

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

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,30 @@
33

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

6-
// =============> write your prediction of the error here
6+
// =============> write your prediction of the error here: error one, 3 cannot be a parameter name, parameters must be variable names, not values.
7+
// Error two, num is not defined. There is no variable named num, it would need to match the name inside the function.
78

8-
function square(3) {
9-
return num * num;
10-
}
9+
//function square(3) {
10+
// return num * num;
11+
//}
12+
13+
// =============> write the error message here:
14+
15+
//Uncaught SyntaxError: Unexpected number
1116

12-
// =============> write the error message here
17+
//Uncaught SyntaxError: Illegal return statement
1318

14-
// =============> explain this error message here
19+
// =============> explain this error message here:
20+
21+
// first error message came up because JS found a number instead of a variable for the function.
22+
// second error message came up because in JS return has to be inside of a function.
1523

1624
// Finally, correct the code to fix the problem
1725

18-
// =============> write your new code here
26+
// =============> write your new code here:
27+
28+
function square(num) {
29+
return num * num;
30+
}
1931

2032

0 commit comments

Comments
 (0)