Skip to content

Commit c9f5c3b

Browse files
committed
Fix variable redeclaration in capitalise function and update predictions and explanations
1 parent 8f3d6cf commit c9f5c3b

File tree

1 file changed

+14
-1
lines changed
  • Sprint-2/1-key-errors

1 file changed

+14
-1
lines changed

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
// Predict and explain first...
2-
// =============> write your prediction here
2+
// =============> write your prediction here
3+
4+
// I predict that the code will throw an error when trying to call the function capitalise with a string input
5+
// because the variable 'str' is being declared twice within the same scope, which is not allowed in JavaScript.
36

47
// call the function capitalise with a string input
58
// interpret the error message and figure out why an error is occurring
@@ -10,4 +13,14 @@ function capitalise(str) {
1013
}
1114

1215
// =============> write your explanation here
16+
17+
// The code will throw a SyntaxError because the variable 'str' is being declared twice within the same scope.
1318
// =============> write your new code here
19+
20+
function capitalise(str) {
21+
str = `${str[0].toUpperCase()}${str.slice(1)}`;
22+
return str;
23+
}
24+
25+
// Example:
26+
console.log(capitalise("hello")); // Output: "Hello"

0 commit comments

Comments
 (0)