-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0.js
More file actions
26 lines (19 loc) · 990 Bytes
/
Copy path0.js
File metadata and controls
26 lines (19 loc) · 990 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// Predict and explain first...
// =============> write your prediction here
// I predict that the function will capitalise the first character of the string
// And then return a string using string interpolation using the first character of the string
// and a slice of the remaining characters of the string excluding the first character.
// call the function capitalise with a string input
// interpret the error message and figure out why an error is occurring
function capitalise(str) {
let str = `${str[0].toUpperCase()}${str.slice(1)}`;
return str;
}
// =============> write your explanation here
// An error is thrown because of the variable name collision. The function has a parameter called `str`
// but in the body of the function, a variable `str` is declared and that conflicts with the parameter.
// =============> write your new code here
function upperCased(string) {
const capitalised = `${string[0].toUpperCase()}${string.slice(1)}`;
return capitalised;
}