Skip to content

Commit 76ef122

Browse files
committed
answered 1-key-errors 0.js
1 parent d28242a commit 76ef122

2 files changed

Lines changed: 25 additions & 3 deletions

File tree

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,26 @@
11
// Predict and explain first...
22
// =============> write your prediction here
3+
//A: when user input the string. First index will be capitalised.
34

45
// call the function capitalise with a string input
56
// interpret the error message and figure out why an error is occurring
7+
//A: SyntaxError: Identifier 'str' has already been declared
68

9+
//function capitalise(str) {
10+
// let str = `${str[0].toUpperCase()}${str.slice(1)}`;
11+
// return str;
12+
//}
13+
14+
15+
// =============> write your explanation here
16+
//"str" has been declared in function. In the local scope of original code, str declared again.
17+
//It caused the problem of redeclaration. Delete the "let" in local scope
18+
// =============> write your new code here
719
function capitalise(str) {
8-
let str = `${str[0].toUpperCase()}${str.slice(1)}`;
20+
str = `${str[0].toUpperCase()}${str.slice(1)}`;
921
return str;
1022
}
1123

12-
// =============> write your explanation here
13-
// =============> write your new code here
24+
console.log(capitalise('roger'))
25+
26+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const password = "secretword123";
2+
3+
function checkPassword(userInput){
4+
5+
const response = userInput === password;
6+
7+
return response;
8+
9+
console.log(checkPassword(secretword123))

0 commit comments

Comments
 (0)