-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2.js
More file actions
37 lines (22 loc) · 1.04 KB
/
Copy path2.js
File metadata and controls
37 lines (22 loc) · 1.04 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
36
37
// Predict and explain first BEFORE you run any code...
// I predict that the code will throw a ReferenceError because the variable 'num' is not defined within the function scope.
// this function should square any number but instead we're going to get an error
//
// =============> write your prediction of the error here
// I predict that the code will throw a ReferenceError because the variable 'num' is not defined within the function scope.
/
function square(3) {
return num * num;
}
// =============> write the error message here
// ReferenceError: num is not defined
// =============> explain this error message here
// This error message indicates that the variable 'num' is being used before it has been declared or defined.
// In the function 'square', the parameter is incorrectly defined as a literal value (3) instead of a variable name.
// Finally, correct the code to fix the problem
// =============> write your new code here
function square(num) {
return num * num;
}
// Example:
console.log(square(3)); // Output: 9