-
-
Notifications
You must be signed in to change notification settings - Fork 337
Expand file tree
/
Copy path0.js
More file actions
22 lines (18 loc) · 903 Bytes
/
0.js
File metadata and controls
22 lines (18 loc) · 903 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// Predict and explain first...
// =============> write your prediction here
// It will give an error because the variable `str`, is declared twice inside the same function,
// It is already a parameter, and then it is redeclared using `let`.
// 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 happens because 'str' is written two times, first, it is the function parameter.
// Then, it is declared again using 'let', javaScript does not allow declaring the same variable twice, inside the same function.
// =============> write your new code here
function capitalise(str) {
return `${str[0].toUpperCase()}${str.slice(1)}`;
}
console.log(capitalise("Code"));