Skip to content

Commit e90b646

Browse files
committed
remove duplicate let declaration of parameter str
1 parent 455e47f commit e90b646

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

  • Sprint-2/1-key-errors

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

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,29 @@
11
// Predict and explain first...
22
// =============> write your prediction here
3+
// I think that there will be a SyntaxError because str is already
4+
// declared as a parameter, and I am trying to re-declare it as
5+
// a variable with let inside the function. This is not allowed in
6+
// Javascript.
37

48
// call the function capitalise with a string input
59
// interpret the error message and figure out why an error is occurring
610

11+
// function capitalise(str) {
12+
// let str = `${str[0].toUpperCase()}${str.slice(1)}`;
13+
// return str;
14+
// }
15+
16+
// =============> write your explanation here
17+
// You can't use let to declare a variable with the same name
18+
// as a parameter in the same function. The parameter str is
19+
// already declared, so when you try to declare it again with let,
20+
// it causes a SyntaxError. To fix this, you can either remove
21+
// let and just assign a new value to str, or you can use a different
22+
// variable name for the capitalised string.
23+
// =============> write your new code here
724
function capitalise(str) {
8-
let str = `${str[0].toUpperCase()}${str.slice(1)}`;
25+
str = `${str[0].toUpperCase()}${str.slice(1)}`;
926
return str;
1027
}
1128

12-
// =============> write your explanation here
13-
// =============> write your new code here
29+
console.log(capitalise("hello"));

0 commit comments

Comments
 (0)