Skip to content

Commit 1564427

Browse files
committed
Parameter defined in function
1 parent 8d3eb4a commit 1564427

File tree

1 file changed

+17
-9
lines changed
  • Sprint-2/1-key-errors

1 file changed

+17
-9
lines changed

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

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,26 @@
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+
// The function does not define the parameter correctly
7+
// Instead, the input has been inserted where the parameter name should be
8+
// Then num is being used in the function body but it is not defined anywhere
79

8-
function square(3) {
9-
return num * num;
10-
}
11-
12-
// =============> write the error message here
10+
// function square(3) {
11+
// return num * num;
12+
// }
1313

14-
// =============> explain this error message here
14+
// SyntaxError: Unexpected number
15+
// The number 3 is used directly in the function parameter
16+
// The function parameter should be num to accept any number as input
17+
// Then the function body can use num to square the input value
18+
//Defining a function should describe the parameters it expects, not specific values
1519

1620
// Finally, correct the code to fix the problem
17-
18-
// =============> write your new code here
21+
function square(num) {
22+
return num * num;
23+
}
24+
console.log(square(5));
25+
console.log(square(10));
26+
console.log(square(-3));
1927

2028

0 commit comments

Comments
 (0)