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
// //My prediction` => The capitalise function tries to capitalize the first character of the string and concat it with the rest. This function may not run as it has error.
3
3
4
4
// call the function capitalise with a string input
5
5
// interpret the error message and figure out why an error is occurring
@@ -9,5 +9,10 @@ function capitalise(str) {
9
9
returnstr;
10
10
}
11
11
12
-
// =============> write your explanation here
13
-
// =============> write your new code here
12
+
// call the function with a string argument
13
+
capitalise("hello world");
14
+
// the error is occurring because we are trying to declare a variable with the same name as the function parameter
Copy file name to clipboardExpand all lines: Sprint-2/1-key-errors/1.js
+12-3Lines changed: 12 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,9 @@
1
1
// Predict and explain first...
2
2
3
+
4
+
3
5
// Why will an error occur when this program runs?
4
-
// =============> write your prediction here
6
+
// The error will occur because the variable 'decimalNumber' is being redeclared.
5
7
6
8
// Try playing computer with the example to work out what is going on
7
9
@@ -14,7 +16,14 @@ function convertToPercentage(decimalNumber) {
14
16
15
17
console.log(decimalNumber);
16
18
17
-
// =============> write your explanation here
19
+
// the error is occurring because we are trying to declare a variable with the same name as the function parameter, which is not allowed in JavaScript.
0 commit comments