Skip to content

Commit e1af344

Browse files
committed
Completed 0.js exercise
1 parent 8f3d6cf commit e1af344

File tree

1 file changed

+13
-0
lines changed
  • Sprint-2/1-key-errors

1 file changed

+13
-0
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
// Predict and explain first...
22
// =============> write your prediction here
33

4+
// I predict that the function will capitalise the first character of the string
5+
// And then return a string using string interpolation using the first character of the string
6+
// and a slice of the remaining characters of the string excluding the first character.
7+
48
// call the function capitalise with a string input
59
// interpret the error message and figure out why an error is occurring
610

@@ -10,4 +14,13 @@ function capitalise(str) {
1014
}
1115

1216
// =============> write your explanation here
17+
18+
// An error is thrown because of the variable name collision. The function has a parameter called `str`
19+
// but in the body of the function, a variable `str` is declared and that conflicts with the parameter.
20+
1321
// =============> write your new code here
22+
23+
function upperCased(string) {
24+
const capitalised = `${string[0].toUpperCase()}${string.slice(1)}`;
25+
return capitalised;
26+
}

0 commit comments

Comments
 (0)