-
-
Notifications
You must be signed in to change notification settings - Fork 335
Expand file tree
/
Copy path0.js
More file actions
25 lines (19 loc) · 863 Bytes
/
0.js
File metadata and controls
25 lines (19 loc) · 863 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
// Predict and explain first...
// =============> write your prediction here
// The program will give an error.The error happens because `str`is written twice inside the function.
// 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 function already has an input called `str`
// Inside the function, the code tries to create another variable called `str`using `let`
//JavaScript does not allow the same varible name to be created again in same place.
//Because of this, the program throwns an error.
// =============> write your new code here
function captialise(str){
str = `${str[0].toUpperCase()}${str.slice(1)}`;
return str;
}