Skip to content

Commit 13dbe89

Browse files
committed
Variable declared twice fixed
1 parent 43a32bb commit 13dbe89

File tree

1 file changed

+15
-1
lines changed
  • Sprint-2/1-key-errors

1 file changed

+15
-1
lines changed

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
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,4 +14,14 @@ function capitalise(str) {
1014
}
1115

1216
// =============> write your explanation here
17+
// an error occured because the variable str was already declared as a parameter of the function so
18+
// there was no need to use let again.
19+
20+
1321
// =============> write your new code here
22+
function capitalise(str) {
23+
str = `${str[0].toUpperCase()}${str.slice(1)}`;
24+
return str;
25+
}
26+
27+
console.log(capitalise("hello"));

0 commit comments

Comments
 (0)