-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0.js
More file actions
18 lines (18 loc) · 821 Bytes
/
Copy path0.js
File metadata and controls
18 lines (18 loc) · 821 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// Predict and explain first...
// =============> write your prediction here
// It will crash with a SyntaxError. We can't use 'let' to declare 'str' because 'str' is already taken by the function parameter.
// call the function capitalise with a string input
// interpret the error message and figure out why an error is occurring
/* I commented this out so it doesn't crash:
function capitalise(str) {
let str = `${str[0].toUpperCase()}${str.slice(1)}`;
return str;
}
*/
// =============> write your explanation here
//The error confirms "str has already been declared". Function parameters act as local variables, creating a naming conflict with `let str`.
// =============> write your new code here
function capitalise(str) {
return `${str[0].toUpperCase()}${str.slice(1)}`;
}
console.log(capitalise("hello"));