Skip to content

Commit 40ac0ad

Browse files
Refactor square function example to correct parameter name and update error explanations
1 parent bf6d021 commit 40ac0ad

File tree

1 file changed

+12
-7
lines changed
  • Sprint-2/1-key-errors

1 file changed

+12
-7
lines changed

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
1-
21
// Predict and explain first BEFORE you run any code...
32

43
// this function should square any number but instead we're going to get an error
54

6-
// =============> write your prediction of the error here
5+
// =============> the code will throw a syntax error because the parameter name '3' is not a valid identifier in JavaScript.
6+
// The error message will likely indicate that there is an unexpected number or that the parameter name is invalid.
77

8-
function square(3) {
9-
return num * num;
10-
}
8+
//function square(3) {
9+
// return num * num;
10+
//}
1111

12-
// =============> write the error message here
12+
// =============> C:\Users\alexo\CYF\Module-Structuring-and-Testing-Data\Module-Structuring-and-Testing-Data\Sprint-2\
13+
// 1-key-errors\2.js:9 function square(3) {SyntaxError: Unexpected number
1314

14-
// =============> explain this error message here
15+
// =============> We get an unexpected number error because the parameter name '3' is not a valid identifier in JavaScript.
1516

1617
// Finally, correct the code to fix the problem
1718

1819
// =============> write your new code here
1920

21+
function square(num) {
22+
return num * num;
23+
}
2024

25+
console.log(square(4));

0 commit comments

Comments
 (0)