File tree Expand file tree Collapse file tree 1 file changed +20
-4
lines changed
Expand file tree Collapse file tree 1 file changed +20
-4
lines changed Original file line number Diff line number Diff line change 11// Predict and explain first...
22// =============> write your prediction here
3+ // code will throw error as the parameter is being redeclared
4+ // in the function.
35
46// call the function capitalise with a string input
57// interpret the error message and figure out why an error is occurring
68
7- function capitalise ( str ) {
8- let str = `${ str [ 0 ] . toUpperCase ( ) } ${ str . slice ( 1 ) } ` ;
9- return str ;
10- }
9+ // function capitalise(str) {
10+ // let str = `${str[0].toUpperCase()}${str.slice(1)}`;
11+ // return str;
12+ // }
1113
1214// =============> write your explanation here
15+
16+ // let str = `${str[0].toUpperCase()}${str.slice(1)}`;
17+ // ^
18+
19+ // SyntaxError: Identifier 'str' has already been declared indicates
20+ // str is being redeclared in the function as it was already declared
21+ // as a parameter of the function capitalise.
22+
1323// =============> write your new code here
24+ function capitalise ( str ) {
25+ let capitalisedStr = `${ str [ 0 ] . toUpperCase ( ) } ${ str . slice ( 1 ) } ` ;
26+ return capitalisedStr ;
27+ }
28+
29+ capitalise ( "hello" ) // 'Hello'
You can’t perform that action at this time.
0 commit comments