Skip to content

Commit 7620265

Browse files
fix: correct parameter name in square function to prevent syntax error and update console log example
1 parent 2fafe6e commit 7620265

File tree

1 file changed

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

1 file changed

+14
-2
lines changed

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,29 @@
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+
// The function is defined incorrectly using a number as a parameter name so it will throw an error when called because looking for an identifier but finds a number instead.
78

8-
function square(3) {
9+
/* function square(3) {
910
return num * num;
1011
}
12+
*/
1113

1214
// =============> write the error message here
15+
/* function square(3) {
16+
^
1317
18+
SyntaxError: Unexpected number
19+
*/
1420
// =============> explain this error message here
21+
// SyntaxError: This means there is something wrong with the way the code is written, so JavaScript cannot understand it.
22+
// unexpected number: This means that the code is trying to use a number where it expects an identifier (like a variable name). In this case, the function parameter is incorrectly named as a number (3) instead of a valid identifier.
1523

1624
// Finally, correct the code to fix the problem
25+
// to fix the problem, we need to change the parameter name to a valid identifier, like "num" or "number".
1726

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

20-
29+
function square(num){
30+
return num * num;
31+
}
32+
console.log(square(10));

0 commit comments

Comments
 (0)