File tree Expand file tree Collapse file tree 1 file changed +14
-5
lines changed
Expand file tree Collapse file tree 1 file changed +14
-5
lines changed Original file line number Diff line number Diff line change 11// Predict and explain first...
2- // =============> write your prediction here
2+ // =============> write your prediction here: We'll get an error message because "str" paramater has been declared already,
3+ //using it again inside the function will clash due to redaclaration.
34
45// call the function capitalise with a string input
56// interpret the error message and figure out why an error is occurring
67
8+ //function capitalise(str) {
9+ // let str = `${str[0].toUpperCase()}${str.slice(1)}`;
10+ // return str;
11+ //}
12+
13+ // =============> write your explanation here: Identifier 'str' has already been declared,
14+ //redaclaration in the same scope throws up the error message
15+ // =============> write your new code here:
716function capitalise ( str ) {
8- let str = `${ str [ 0 ] . toUpperCase ( ) } ${ str . slice ( 1 ) } ` ;
9- return str ;
17+ let newStr = `${ str [ 0 ] . toUpperCase ( ) } ${ str . slice ( 1 ) } ` ;
18+ return newStr ;
1019}
1120
12- // =============> write your explanation here
13- // =============> write your new code here
21+ //Above code works because we have used another variable "newStr", avoiding redeclaration.
22+
You can’t perform that action at this time.
0 commit comments