Skip to content

Commit 607ca58

Browse files
committed
Change a literal numerical value as parameter for a variable expect by a function
1 parent 992f376 commit 607ca58

File tree

1 file changed

+15
-1
lines changed
  • Sprint-2/1-key-errors

1 file changed

+15
-1
lines changed

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,31 @@
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+
// This code will throw a SyntaxError because function parameters must be valid variable names,
8+
// not literal values like 3.
79

10+
/**
811
function square(3) {
912
return num * num;
1013
}
14+
*/
1115

1216
// =============> write the error message here
17+
// SyntaxError: Unexpected number
18+
// (or "SyntaxError: Unexpected token '3'" depending on the environment)
1319

1420
// =============> explain this error message here
15-
21+
// The error occurs because JavaScript expects a variable name (like num or x) inside the parentheses
22+
// of a function definition. You cannot use a number (3) as a parameter name — it’s not a valid identifier.
23+
// Function parameters act as variable placeholders for input values, so they must follow variable naming rules.
24+
//
1625
// Finally, correct the code to fix the problem
1726

1827
// =============> write your new code here
1928

29+
function square(num) {
30+
return num * num;
31+
}
32+
33+
console.log(square(3)); // Output: 9
2034

0 commit comments

Comments
 (0)