File tree Expand file tree Collapse file tree 1 file changed +18
-4
lines changed
Expand file tree Collapse file tree 1 file changed +18
-4
lines changed Original file line number Diff line number Diff line change 11// Predict and explain first...
22// =============> write your prediction here
3+
4+ // The code will capitalize the first word of the str which gives "Str"
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+ // The error occurs in line 13 and it says "SyntaxError: Identifier 'str' has already been declared"
10+ // The error is informing us that the string str has already been declared in line 12 so we can not declare it again.
11+
12+ //function capitalise(str) {
13+ // let str = `${str[0].toUpperCase()}${str.slice(1)}`;
14+ // return str;
15+ //}
1116
1217// =============> write your explanation here
18+
19+ // The code is written to capitalize the first letter of str which is expected to give the result Str.
20+
1321// =============> write your new code here
22+
23+ function capitalise ( str ) {
24+ str = `${ str [ 0 ] . toUpperCase ( ) } ${ str . slice ( 1 ) } ` ;
25+ return str ;
26+ }
27+ console . log ( capitalise ( "str" ) )
You can’t perform that action at this time.
0 commit comments