Skip to content

Commit d973f84

Browse files
committed
Removed redeclaration in capitalise() function
1 parent 265ee10 commit d973f84

File tree

1 file changed

+8
-0
lines changed
  • Sprint-2/1-key-errors

1 file changed

+8
-0
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Predict and explain first...
22
// =============> write your prediction here
3+
// It will show an error message
34

45
// call the function capitalise with a string input
56
// interpret the error message and figure out why an error is occurring
@@ -8,6 +9,13 @@ function capitalise(str) {
89
let str = `${str[0].toUpperCase()}${str.slice(1)}`;
910
return str;
1011
}
12+
capitalise("Hello");
1113

1214
// =============> write your explanation here
15+
// SyntaxError: Identifier 'str' has already been declared - This error means that the variable 'str' was declared more than once in the same scope.
16+
// JavaScrip doesn't allow that - once a variable name is declared with let or const, you can't declare it again.
1317
// =============> write your new code here
18+
function capitalise(str) {
19+
return str[0].toUpperCase() + str.slice(1);
20+
}
21+

0 commit comments

Comments
 (0)