Skip to content

Commit 6959f9a

Browse files
committed
�[200~Variable declared twice fixed
1 parent 8f3d6cf commit 6959f9a

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
node_modules
22
.DS_Store
33
.vscode
4+
testing.js --- IGNORE ---
45
**/.DS_Store

Sprint-2/1-key-errors/0.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
// Predict and explain first...
2-
// =============> write your prediction here
2+
// The code has a function that is supposed to capitalise the string passed to it. (only the first letter)
3+
// the string will be stored in the variable str and the function will return its value.
4+
// it takes the first letter (str[0]) and uses toUpperCase() method to capitalise it.
5+
// the str.slice(1) method is used to show the letter.
6+
//
37

48
// call the function capitalise with a string input
59
// interpret the error message and figure out why an error is occurring
10+
@@ -10,4 +14,14 @@ function capitalise(str) {
11+
}
12+
13+
// =============> write your explanation here
14+
// an error occured because the variable str was already declared as a parameter of the function so
15+
// there was no need to use let again.
16+
617

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("hello"));

testing.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
function capitaliseFirstLetter(string){
2+
string = `${string[0].toUpperCase()}`;
3+
return string;
4+
}
5+
6+
console.log(capitaliseFirstLetter("hello"));

0 commit comments

Comments
 (0)