File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed
Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change 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+ // Prediction: It will throw a syntax error because 3 is not a valid parameter name.
78
9+ /* Original Code:
810function square(3) {
911 return num * num;
1012}
13+ */
1114
1215// =============> write the error message here
16+ // SyntaxError: Unexpected number
1317
1418// =============> explain this error message here
19+ // MDN Reference: https://developer.mozilla.org/en-US/docs/Glossary/Identifier
20+
21+ // JavaScript does not allow numbers to be used as variable names or parameter names.
22+ // Function parameters must follow the rules for valid identifiers.
23+ // According to MDN, an identifier may not start with a digit and must follow JavaScript's naming rules.
1524
1625// Finally, correct the code to fix the problem
1726
1827// =============> write your new code here
28+ function square ( num ) {
29+ return num * num ;
30+ }
31+
32+ console . log ( square ( 3 ) ) ; // 9
1933
34+ // Test cases:
2035
36+ // console.log(square(10)); // 100
37+ // console.log(square(5)); // 25
You can’t perform that action at this time.
0 commit comments