Skip to content

Commit 13fc59b

Browse files
committed
Fix variable redeclaration in capitalise function
1 parent d28242a commit 13fc59b

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

  • Sprint-3/1-key-errors

‎Sprint-3/1-key-errors/0.js‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,17 @@ function capitalise(str) {
1010
}
1111

1212
// =============> write your explanation here
13+
//The error occurs because the variable "str" is being
14+
//declared twice in the same scope. The parameter "str"
15+
//is already defined as a function argument, and then it
16+
//is being redeclared with "let str =". This causes
17+
//a syntax error because we cannot declare a variable
18+
//with the same name in the same scope. To fix this, we
19+
//can either rename the parameter or the variable inside
20+
//the function.
21+
1322
// =============> write your new code here
23+
function capitalise(str) {
24+
let capitalisedStr = `${str[0].toUpperCase()}${str.slice(1)}`;
25+
return capitalisedStr;
26+
}

0 commit comments

Comments
 (0)