Skip to content

Commit 9e6672f

Browse files
fix the error
1 parent a9e44ee commit 9e6672f

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

  • Sprint-3/1-key-errors

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
// Predict and explain first...
2-
// =============> write your prediction here
2+
// function parameter and variable inside the function have same name.
33

44
// call the function capitalise with a string input
5+
console.log(capitalise("message"));
56
// interpret the error message and figure out why an error is occurring
6-
7-
function capitalise(str) {
8-
let str = `${str[0].toUpperCase()}${str.slice(1)}`;
9-
return str;
10-
}
7+
/*Identifier 'str' has already been declared .
8+
This mean that 'str' has already been declared as a function parameter,
9+
so we cannot declare another variable with the same name using 'let'.
10+
*/
1111

1212
// =============> write your explanation here
13+
// The error occurs because 'str' is already declare as a function parameter.
14+
//The 'let str' inside the function tries to declare 'str' again in the same scope.
15+
//I changed the name of new variable to 'result' to fix the error.
16+
1317
// =============> write your new code here
18+
function capitalise(str) {
19+
let result = `${str[0].toUpperCase()}${str.slice(1)}`;
20+
return result;
21+
}

0 commit comments

Comments
 (0)