Skip to content

Commit 9bf321e

Browse files
committed
Fix variable redeclaration error in capitalise function and update explanation
1 parent abb3aa5 commit 9bf321e

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

  • Sprint-2/1-key-errors

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,10 @@ function capitalise(str) {
99
return str;
1010
}
1111

12-
// =============> write your explanation here
12+
// =============> SyntaxError: Identifier 'str' has already been declared. This error occurs because the variable 'str' is being declared again within the function,
13+
// which is not allowed. To fix this, we can simply remove the 'let' declaration.
1314
// =============> write your new code here
15+
function capitalise(str) {
16+
return `${str[0].toUpperCase()}${str.slice(1)}`;
17+
}
18+
console.log(capitalise("brother"));

0 commit comments

Comments
 (0)