File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed
Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change 44// this function should square any number but instead we're going to get an error
55
66// =============> write your prediction of the error here
7+ /* I predict that the code will throw a SyntaxError because the parameter '3' is not a valid identifier.
8+ Function parameters must be valid variable names.*/
9+
10+ /*
711
812function square(3) {
913 return num * num;
1014}
1115
16+ */
17+
1218// =============> write the error message here
19+ /* Process exited with code 1
20+ Uncaught SyntaxError /home/ads/Desktop/CYF-SEP/Module-Structuring-and-Testing-Data/Sprint-2/1-key-errors/2.js:10
21+ function square(3) {
22+ ^
23+
24+ SyntaxError: Unexpected number */
1325
1426// =============> explain this error message here
27+ /* The error message indicates a SyntaxError due to an "Unexpected number". This occurs because the function
28+ parameter '3' is not a valid identifier. In JavaScript, function parameters must be valid variable names, and
29+ using a number as a parameter name is not allowed. The JavaScript engine expects a valid identifier after the
30+ opening parenthesis of the function declaration, but it encounters a number instead, leading to the syntax error.*/
1531
1632// Finally, correct the code to fix the problem
1733
1834// =============> write your new code here
1935
36+ function square ( num ) {
37+ return num * num ;
38+ }
2039
40+ console . log ( square ( 4 ) ) ; // Output: 16
You can’t perform that action at this time.
0 commit comments