You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Sprint-2/1-key-errors/0.js
-1Lines changed: 0 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,6 @@ function capitalise(str) {
14
14
// The error occurs because we are trying to declare a new variable 'str' inside the function, which is already declared as a parameter. In JavaScript, you cannot declare a variable with the same name as a parameter within the same scope. To fix this error, we can simply remove the 'let' keyword and assign the new value to the existing parameter 'str' instead of trying to redeclare it.
Copy file name to clipboardExpand all lines: Sprint-2/1-key-errors/2.js
+10-2Lines changed: 10 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -4,17 +4,25 @@
4
4
// this function should square any number but instead we're going to get an error
5
5
6
6
// =============> write your prediction of the error here
7
+
// I predict that error will occur because the parameter 'num' is not defined in the function.
7
8
8
9
functionsquare(3){
10
+
9
11
returnnum*num;
10
12
}
11
13
12
14
// =============> write the error message here
13
-
15
+
// Uncaught SyntaxError: Unexpected number
16
+
// =============> explain this error message here
17
+
// The error occurs because we are trying to use a number '3' as a parameter in the function declaration, which is not valid syntax in JavaScript.
18
+
// Parameters should be variable names, not literal values. To fix this error, we can replace '3' with a valid variable name like 'num'.
14
19
// =============> explain this error message here
20
+
// To fix this error, we can change the parameter from '3' to a valid variable name like 'num'. This way, we can pass any number as an argument when calling the function, and it will correctly return the square of that number.
0 commit comments