Skip to content

Commit 0c7cc6f

Browse files
committed
corrected the error with the function
1 parent 5ab6322 commit 0c7cc6f

File tree

1 file changed

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

1 file changed

+10
-7
lines changed

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
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
6+
//it will throw an error for use of a primitive value instead of a variable.
77

8-
function square(3) {
9-
return num * num;
10-
}
8+
//function square(3) {
9+
// return num * num;
10+
//}
1111

12-
// =============> write the error message here
12+
// =============> write the error message here, SyntaxError: Unexpected number
1313

1414
// =============> explain this error message here
15-
15+
//this error message is becasue we cannot pass a direct value to a function when creating it but rather when we call it. Instead we need to give it a parameter that can then hold the value that we want to pass to the function.
1616
// Finally, correct the code to fix the problem
1717

1818
// =============> write your new code here
19+
function square(num) {
20+
return num * num;
21+
}
1922

20-
23+
console.log(square(3));

0 commit comments

Comments
 (0)