Skip to content

Commit 5f75bcf

Browse files
committed
Predicted, explained and fixed the error
1 parent 4fef432 commit 5f75bcf

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

  • Sprint-3/1-key-errors

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,27 @@
11
// Predict and explain first...
22
// =============> write your prediction here
3+
// capitalise function takes 1 str arg
4+
// let srting will give an error if i try to pass my string.
5+
// remove let
6+
// str is being put in template literal
7+
// str[0]: 1st index of str becomes uppercase
8+
// str.slice(1): 2nd index slice until end of str
9+
// str = "frankocean"
10+
// return = "Frankocean"
11+
312

413
// call the function capitalise with a string input
514
// interpret the error message and figure out why an error is occurring
615

716
function capitalise(str) {
8-
let str = `${str[0].toUpperCase()}${str.slice(1)}`;
17+
str = `${str[0].toUpperCase()}${str.slice(1)}`;
918
return str;
1019
}
1120

1221
// =============> write your explanation here
22+
// let str = `${str[0].toUpperCase()}${str.slice(1)}`;
23+
// I was right, error given is because of let str within the function.
24+
// SyntaxError: Identifier 'str' has already been declared
25+
// We cannot have two declarations of the same variable so we remove the let inside .capitalise.
1326
// =============> write your new code here
27+
console.log(capitalise("frankocean"))

0 commit comments

Comments
 (0)