Skip to content

Commit 47a9c16

Browse files
committed
Complete error exercise 0 - capitalise redeclare
1 parent f5b9e81 commit 47a9c16

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

  • Sprint-3/1-key-errors

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
// Predict and explain first...
2-
// =============> write your prediction here
3-
2+
// =============> write your prediction here==> SyntaxError because str is declared twice (parameter + let)
43
// call the function capitalise with a string input
54
// interpret the error message and figure out why an error is occurring
6-
5+
//function capitalise(str) {
6+
// let str = `${str[0].toUpperCase()}${str.slice(1)}`;
7+
// return str;
8+
//}
9+
// =============> write your explanation here==> (let str) will make a syntaxerror because str is already declared as parameter in the function: [function capitalise(str) ] and we can not declare an identifier in the same scope
10+
// =============> write your new code here:
711
function capitalise(str) {
8-
let str = `${str[0].toUpperCase()}${str.slice(1)}`;
9-
return str;
12+
str = `${str[0].toUpperCase()}${str.slice(1)}`;
13+
return str;
1014
}
11-
12-
// =============> write your explanation here
13-
// =============> write your new code here
15+
console.log(capitalise("hello world"));

0 commit comments

Comments
 (0)