Skip to content

Commit e3e39a8

Browse files
I added my predication and explaiened that an error will occur because the function paramater name is unvaild number . and changed the code after trying it by changing the function name to num be decalred and to work when I call the function.
1 parent f18f2af commit e3e39a8

File tree

1 file changed

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

1 file changed

+19
-4
lines changed

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

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,32 @@
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 error will occur because the paramater of the function is not a valid variable name as it is a number.
8+
// also the variable num is not declared in the function and this will give an error when the program run because the function will not know what the value of the num is.
79

810
function square(3) {
911
return num * num;
1012
}
1113

12-
// =============> write the error message here
14+
// =============> write the error message here
15+
// function square(3) {
16+
// ^
1317

14-
// =============> explain this error message here
18+
// SyntaxError: Unexpected number
1519

16-
// Finally, correct the code to fix the problem
20+
// =============> explain this error message here it means that the paramater of the function is an unexpected number (3) and this is not a valid variable number.
21+
I deleted the paramater of the function and run the programe and I get this error:
22+
/box/index.js:2
23+
return num * num;
24+
^
1725

18-
// =============> write your new code here
26+
ReferenceError: num is not defined
1927

2028

29+
// Finally, correct the code to fix the problem
30+
change the function to this: function square(num)
31+
// =============> write your new code here
32+
function square(num) {
33+
return num * num;
34+
}
35+
console.log(square(3));

0 commit comments

Comments
 (0)