-
-
Notifications
You must be signed in to change notification settings - Fork 335
Expand file tree
/
Copy path2.js
More file actions
35 lines (25 loc) · 1.16 KB
/
2.js
File metadata and controls
35 lines (25 loc) · 1.16 KB
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
35
// 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
the error will occur because the paramater of the function is not a valid variable name as it is a number.
also the variable num is not declared in the function and this will give an error when the program run because the function will not know what the value of the num is.
function square(3) {
return num * num;
}
// =============> write the error message here
function square(3) {
^
SyntaxError: Unexpected number
// =============> explain this error message here it means that the paramater of the function is an unexpected number (3) and this is not a valid variable number.
I deleted the paramater of the function and run the programe and I get this error:
/box/index.js:2
return num * num;
^
ReferenceError: num is not defined
// Finally, correct the code to fix the problem
change the function to this: function square(num)
// =============> write your new code here
function square(num) {
return num * num;
}
console.log(square(3));