Skip to content

Commit 38c5f48

Browse files
committed
Predict and explain errors. Fix by removing let so not to make new variable with same name
1 parent d28242a commit 38c5f48

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

  • Sprint-3/1-key-errors

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
// Predict and explain first...
22
// =============> write your prediction here
3+
// the function has a parameter str, but then tries to make a new
4+
// variable also called str. so maybe cause error because str already exists
35

46
// call the function capitalise with a string input
57
// interpret the error message and figure out why an error is occurring
68

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

1214
// =============> write your explanation here
15+
// SyntaxError: Identifier 'str' has already been declared
16+
// Prediction was correct, str already exists
1317
// =============> write your new code here
18+
19+
function capitalise(str) {
20+
str = `${str[0].toUpperCase()}${str.slice(1)}`;
21+
return str;
22+
}

0 commit comments

Comments
 (0)