-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2.js
More file actions
34 lines (23 loc) · 990 Bytes
/
Copy path2.js
File metadata and controls
34 lines (23 loc) · 990 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Predict and explain first BEFORE you run any code...
// This function should square any number but instead we're going to get an error
// =============> write your prediction of the error here
// function square(3) {
// return num * num;
// }
// =============> write the error message here
// /home/justice/Documents/CYF/Module-Structuring-and-Testing-Data/Sprint-2/1-key-errors/2.js:8
// function square(3) {
// ^
// The SyntaxError: Unexpected number
// =============> explain this error message here
// This occurs because the number "3" is used as a function parameter.
// This is not valid syntax. A function parameter must be a valid variable name (an identifier),
// not a number. JavaScript expects an identifier or no parameter at all.
// That's why it throws a syntax error.
//
// Finally, correct the code to fix the problem
// =============> write your new code here
function square(num) {
return num * num;
}
console.log(square(3));