Skip to content

Commit ff84a76

Browse files
Fix redeclaration error in capitalise function
Renamed variable 'str' to 'result' to avoid redeclaration error.
1 parent b31a586 commit ff84a76

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

  • Sprint-2/1-key-errors

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
// Predict and explain first...
2-
// =============> write your prediction here
3-
2+
// =============> I presume the str is repeatedly declared, first as a parameter and again as a variable.
43
// call the function capitalise with a string input
54
// interpret the error message and figure out why an error is occurring
65

6+
77
function capitalise(str) {
88
let str = `${str[0].toUpperCase()}${str.slice(1)}`;
99
return str;
1010
}
1111

12-
// =============> write your explanation here
13-
// =============> write your new code here
12+
13+
// =============> str is already declared in the parameter and shouldn't be declared inside the function. The error says it's been declared already for this reason. Therefore we need to rename the str inside the function.
14+
/* ==========> function capitalise(str) {
15+
let result = `${str[0].toUpperCase()}${str.slice(1)};
16+
return result;
17+
}
18+
OR
19+
function capitalise(str) {
20+
return `${str[0].toUpperCase()}${str.slice(1)}`;
21+
}
22+
*/
23+

0 commit comments

Comments
 (0)