File tree Expand file tree Collapse file tree 1 file changed +11
-0
lines changed
Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change 11// Predict and explain first...
22// =============> write your prediction here
3+ // I predict there will be a syntax error but not sure what the error is yet. I think it has something to do with the variable declaration of str.
34
45// call the function capitalise with a string input
56// interpret the error message and figure out why an error is occurring
@@ -9,5 +10,15 @@ function capitalise(str) {
910 return str ;
1011}
1112
13+ console . log ( capitalise ( "hello world" ) ) ;
1214// =============> write your explanation here
15+ // it showed SyntaxError: Identifier 'str' has already been declared, this is because we have declared the variable str twice,
16+ // once as a parameter and once as a variable inside the function. To fix this error, we can either change the name of the
17+ // variable inside the function to something else like newStr.
1318// =============> write your new code here
19+ function capitalise ( str ) {
20+ let newStr = `${ str [ 0 ] . toUpperCase ( ) } ${ str . slice ( 1 ) } ` ;
21+ return newStr ;
22+ }
23+
24+ console . log ( capitalise ( "hello world" ) ) ;
You can’t perform that action at this time.
0 commit comments