Skip to content

Commit ce0868b

Browse files
committed
questions answered and code fixed
1 parent 3d852fa commit ce0868b

File tree

1 file changed

+20
-0
lines changed
  • Sprint-2/1-key-errors

1 file changed

+20
-0
lines changed

Sprint-2/1-key-errors/2.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,37 @@
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
812
function 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

0 commit comments

Comments
 (0)