Skip to content

Commit 763574c

Browse files
fixed the function to return the square of a number by replacing the parameter
1 parent 686be02 commit 763574c

File tree

1 file changed

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

1 file changed

+18
-7
lines changed

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

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,29 @@
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+
// undefined, because "num" isn't used as a parameter
77

8-
function square(3) {
9-
return num * num;
10-
}
8+
// function square(3) {
9+
// return num * num;
10+
// }
11+
12+
// /Users/cyf/Desktop/CYF/Module-Structuring-and-Testing-Data/Sprint-2/1-key-errors/2.js:8
13+
// function square(3) {
14+
// ^
1115

12-
// =============> write the error message here
16+
// SyntaxError: Unexpected number
1317

14-
// =============> explain this error message here
18+
19+
// the first line tells us where the error occurs:root,folder,file,line
20+
//second line shows exactly which piece of code throws the error
21+
//third line tells us which type of error it is, in this case it is a SyntaxError, meaning that the code wasnt written according to the rules of js,
22+
//an finally it tells us what went wrong
1523

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

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

30+
console.log(square(3));
2031

0 commit comments

Comments
 (0)