Skip to content

Commit 62dc90f

Browse files
authored
Fixed redeclaration error in capitalise function
Updated variable name to avoid redeclaration error.
1 parent 3372770 commit 62dc90f

File tree

1 file changed

+14
-5
lines changed
  • Sprint-2/1-key-errors

1 file changed

+14
-5
lines changed

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
// Predict and explain first...
2-
// =============> write your prediction here
2+
// =============> write your prediction here: We'll get an error message because "str" paramater has been declared already,
3+
//using it again inside the function will clash due to redaclaration.
34

45
// call the function capitalise with a string input
56
// interpret the error message and figure out why an error is occurring
67

8+
//function capitalise(str) {
9+
// let str = `${str[0].toUpperCase()}${str.slice(1)}`;
10+
// return str;
11+
//}
12+
13+
// =============> write your explanation here: Identifier 'str' has already been declared,
14+
//redaclaration in the same scope throws up the error message
15+
// =============> write your new code here:
716
function capitalise(str) {
8-
let str = `${str[0].toUpperCase()}${str.slice(1)}`;
9-
return str;
17+
let newStr = `${str[0].toUpperCase()}${str.slice(1)}`;
18+
return newStr;
1019
}
1120

12-
// =============> write your explanation here
13-
// =============> write your new code here
21+
//Above code works because we have used another variable "newStr", avoiding redeclaration.
22+

0 commit comments

Comments
 (0)