Skip to content

Commit 8cfcf96

Browse files
committed
completion of 1-key-errors
1 parent 2068031 commit 8cfcf96

File tree

1 file changed

+10
-6
lines changed
  • Sprint-2/1-key-errors

1 file changed

+10
-6
lines changed

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,21 @@
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-
8-
function square(3) {
9-
return num * num;
10-
}
7+
// The error will occur because we are trying to declare a function with a parameter that is not a valid variable name. The parameter '3' is not a valid variable name in JavaScript, and this will likely result in a syntax error.
8+
//function square(3) {
9+
// return num * num;
10+
//}
1111

1212
// =============> write the error message here
13-
13+
// SyntaxError: Unexpected number '3'
1414
// =============> explain this error message here
15-
15+
// The error message is indicating that there is a syntax error in the code because we are trying to use a number '3' as a parameter name in the function declaration, which is not allowed in JavaScript. Parameter names must be valid identifiers, which cannot start with a number. To fix this error, we need to change the parameter name to a valid identifier, such as 'num' or 'x'. So we would change the line to: function square(num) { return num * num; }
1616
// Finally, correct the code to fix the problem
1717

1818
// =============> write your new code here
19+
function square(num) {
20+
return num * num;
21+
}
22+
console.log(square(3));
1923

2024

0 commit comments

Comments
 (0)