-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0.js
More file actions
29 lines (25 loc) · 1.1 KB
/
Copy path0.js
File metadata and controls
29 lines (25 loc) · 1.1 KB
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
27
28
29
// Predict and explain first...
// =============> write your prediction here
// I guess the function is trying to capitalise the first letter of the string,
// capture the rest of the string from index 1 to the end of the string,
// and concatenate them together to return the capitalised string
// 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
// After calling the function capitalise with a string input,
// I got a syntax error that "str" has already been declared.
// This is because str has already been declared as a parameter of the function,
// when a new variable named str, it causes a conflict.
// =============> write your new code here
// I renamed the new variable to capitalisedStr to avoid the conflict
function capitalise(str) {
let capitalisedStr = `${str[0].toUpperCase()}${str.slice(1)}`;
return capitalisedStr;
}
console.log(capitalise("hello")); // should return "Hello"