Skip to content

Commit e3b695c

Browse files
committed
Fix function definition to use a parameter instead of a direct input
1 parent 598232d commit e3b695c

File tree

1 file changed

+21
-3
lines changed
  • Sprint-2/1-key-errors

1 file changed

+21
-3
lines changed

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

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,35 @@
44
// this function should square any number but instead we're going to get an error
55

66
// =============> write your prediction of the error here
7+
// I think this is an obvious one because when defining a function you cant give a direct input like 3,
8+
// instead you have to give a variable name as a parameter and then use that variable name in the function
9+
// body to perform the calculation. So I predict that there will be a syntax error because of the way
10+
// the function is defined with a direct input of 3 instead of a variable name.
11+
12+
// function square(3) {
13+
// return num * num;
14+
// }
15+
716

8-
function square(3) {
9-
return num * num;
10-
}
1117

1218
// =============> write the error message here
19+
// /Users/me/CYF/Module-Structuring-and-Testing-Data/Sprint-2/1-key-errors/2.js:12
20+
// function square(3) {
21+
// ^
22+
23+
// SyntaxError: Unexpected number
1324

1425
// =============> explain this error message here
26+
// This error message is saying that there is an unexpected number in the function definition, which is the number 3.
1527

1628
// Finally, correct the code to fix the problem
1729

1830
// =============> write your new code here
1931

32+
function square(num) {
33+
return num * num;
34+
}
35+
36+
console.log(square(3));
37+
2038

0 commit comments

Comments
 (0)