File tree Expand file tree Collapse file tree 1 file changed +18
-1
lines changed
Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change 11
22// Predict and explain first BEFORE you run any code...
33
4+ // I predict that the code will throw a ReferenceError because the variable 'num' is not defined within the function scope.
5+
46// this function should square any number but instead we're going to get an error
57
8+ //
9+
610// =============> write your prediction of the error here
711
12+ // I predict that the code will throw a ReferenceError because the variable 'num' is not defined within the function scope.
13+
14+ /
15+
816function square ( 3 ) {
917 return num * num ;
1018}
1119
1220// =============> write the error message here
1321
22+ // ReferenceError: num is not defined
23+
1424// =============> explain this error message here
1525
26+ // This error message indicates that the variable 'num' is being used before it has been declared or defined.
27+ // In the function 'square', the parameter is incorrectly defined as a literal value (3) instead of a variable name.
28+
1629// Finally, correct the code to fix the problem
1730
1831// =============> write your new code here
1932
20-
33+ function square ( num ) {
34+ return num * num ;
35+ }
36+ // Example:
37+ console . log ( square ( 3 ) ) ; // Output: 9
You can’t perform that action at this time.
0 commit comments