Skip to content

Commit 328f55f

Browse files
committed
Fix capitalise function error
1 parent d28242a commit 328f55f

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

  • Sprint-3/1-key-errors

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
// Predict and explain first...
2-
// =============> write your prediction here
2+
// Prediction: I predict that the code will produce an error because
3+
// str is already declared as a function parameter and is declared
4+
// again with let.
35

46
// call the function capitalise with a string input
57
// interpret the error message and figure out why an error is occurring
68

79
function capitalise(str) {
8-
let str = `${str[0].toUpperCase()}${str.slice(1)}`;
9-
return str;
10+
return `${str[0].toUpperCase()}${str.slice(1)}`;
1011
}
1112

12-
// =============> write your explanation here
13-
// =============> write your new code here
13+
// Explanation: The parameter str is already declared when the
14+
// function is created. We cannot declare another variable called
15+
// str with let in the same scope.
16+
17+
// New code:
18+
// The function now uses the existing str parameter and returns
19+
// the capitalised string.
20+
21+
console.log(capitalise("hello"));

0 commit comments

Comments
 (0)