Skip to content

Commit a8d716b

Browse files
committed
Add code predictions, explanations, and corrections
- Predict the behavior of the existing code and provide explanations. - Include any error messages encountered during execution. - Provide the corrected code to fix the errors.
1 parent aca4398 commit a8d716b

File tree

1 file changed

+16
-4
lines changed
  • Sprint-2/1-key-errors

1 file changed

+16
-4
lines changed

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

Lines changed: 16 additions & 4 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+
// When the code is being read or parsed by Node, it will throw a syntax error because it cannot interpret the number 3 inside the parentheses.
8+
// This is because a number (3) is not a valid parameter name in a function definition.
79

8-
function square(3) {
9-
return num * num;
10-
}
1110

12-
// =============> write the error message here
11+
//function square(3) {
12+
// return num * num;
13+
//}
1314

15+
// =============> write the error message here
16+
// SyntaxError: Unexpected number
1417
// =============> explain this error message here
18+
// This error message indicates that JavaScript only allows identifiers as parameters in a function definition.
19+
// If a literal value (such as a number, string, or object) is used instead, a SyntaxError will be thrown.
20+
1521

1622
// Finally, correct the code to fix the problem
1723

1824
// =============> write your new code here
25+
function square(num) {
26+
return num * num;
27+
}
28+
29+
const actualOutput = square(3);
30+
console.log(actualOutput);
1931

2032

0 commit comments

Comments
 (0)