Skip to content

Commit 15e3b83

Browse files
committed
explaining error msg and fix the code
1 parent 3bdfb60 commit 15e3b83

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

  • Sprint-3/1-key-errors

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
// Predict and explain first...
22
// =============> write your prediction here
3-
3+
//- we expect a syntaxerror because "str" is already declared as function parameter and again as a variable within the same function scope.
44
// call the function capitalise with a string input
55
// interpret the error message and figure out why an error is occurring
6+
//"Error: SyntaxError: Identifier 'str' has already been declared" why: because "str" declared twice.
67

7-
function capitalise(str) {
8-
let str = `${str[0].toUpperCase()}${str.slice(1)}`;
9-
return str;
10-
}
8+
// function capitalise(str) {
9+
// let str = `${str[0].toUpperCase()}${str.slice(1)}`;
10+
// return str;
11+
// }
1112

1213
// =============> write your explanation here
14+
//- I changed the variable name to "strg" to avoid the error.
1315
// =============> write your new code here
16+
function capitalise(str) {
17+
let strg = `${str[0].toUpperCase()}${str.slice(1)}`;
18+
return strg;
19+
}

0 commit comments

Comments
 (0)