Skip to content

Commit 5433734

Browse files
committed
Refactor capitalise function to avoid SyntaxError by renaming variable
1 parent f76aa55 commit 5433734

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

  • Sprint-3/1-key-errors

‎Sprint-3/1-key-errors/0.js‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,18 @@
77
// interpret the error message and figure out why an error is occurring
88
// Error message interpreted ====> The error message simply means the name 'str' was declared twice in the same scope
99

10-
function capitalise(str) {
11-
let str = `${str[0].toUpperCase()}${str.slice(1)}`;
12-
return str;
13-
}
14-
capitalise("moses");
10+
// function capitalise(str) {
11+
// let str = `${str[0].toUpperCase()}${str.slice(1)}`;
12+
// return str;
13+
// }
14+
// capitalise("moses");
1515
// =============> write your explanation here
1616
// The error here is because the parameter 'str' and the variable 'let str' share the same name in he same scope, thus the SyntaxError.
1717
// To fix this error, I could either give the variable a different name or reassign the parameter 'str' without 'let', since no new declaration is made
1818

1919
// =============> write your new code here
20+
function capitalise(str) {
21+
let capitalised = `${str[0].toUpperCase()}${str.slice(1)}`;
22+
return capitalised;
23+
}
24+
console.log(capitalise("moses"));

0 commit comments

Comments
 (0)