Skip to content

Commit 56c1ae7

Browse files
committed
remove duplicate variable declaration in capitalise function
1 parent 7d36f59 commit 56c1ae7

File tree

1 file changed

+13
-4
lines changed
  • Sprint-2/1-key-errors

1 file changed

+13
-4
lines changed

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
// Predict and explain first...
22
// =============> write your prediction here
3+
// It will give an error because the variable `str`, is declared twice inside the same function,
4+
// It is already a parameter, and then it is redeclared using `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

7-
function capitalise(str) {
8-
let str = `${str[0].toUpperCase()}${str.slice(1)}`;
9-
return str;
10-
}
9+
//function capitalise(str) {
10+
// let str = `${str[0].toUpperCase()}${str.slice(1)}`;
11+
// return str;
12+
// }
1113

1214
// =============> write your explanation here
15+
// The error happens because 'str' is written two times, first, it is the function parameter.
16+
// Then, it is declared again using 'let', javaScript does not allow declaring the same variable twice, inside the same function.
1317
// =============> write your new code here
18+
19+
function capitalise(str) {
20+
return `${str[0].toUpperCase()}${str.slice(1)}`;
21+
}
22+
console.log(capitalise("Code"));

0 commit comments

Comments
 (0)