-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0.js
More file actions
21 lines (16 loc) · 812 Bytes
/
Copy path0.js
File metadata and controls
21 lines (16 loc) · 812 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// Predict and explain first...
// =============> write your prediction here
// 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
// The error is occurring because we are trying to declare a variable with the same name as the function parameter 'str'. This causes a conflict and results in a SyntaxError. To fix this, we can simply remove the 'let' keyword and assign the new value to 'str' directly, since 'str' is already defined as a parameter.
// =============> write your new code here
function capitalise(str) {
str = `${str[0].toUpperCase()}${str.slice(1)}`;
return str;
}