File tree Expand file tree Collapse file tree 3 files changed +22
-4
lines changed
Expand file tree Collapse file tree 3 files changed +22
-4
lines changed Original file line number Diff line number Diff line change 11node_modules
22.DS_Store
33.vscode
4+ testing.js --- IGNORE ---
45** /.DS_Store
Original file line number Diff line number Diff line change 11// Predict and explain first...
2- // =============> write your prediction here
2+ // The code has a function that is supposed to capitalise the string passed to it. (only the first letter)
3+ // the string will be stored in the variable str and the function will return its value.
4+ // it takes the first letter (str[0]) and uses toUpperCase() method to capitalise it.
5+ // the str.slice(1) method is used to show the letter.
6+ //
37
48// call the function capitalise with a string input
59// interpret the error message and figure out why an error is occurring
10+ @@ - 10 , 4 + 14 , 14 @@ function capitalise ( str ) {
11+ }
12+
13+ // =============> write your explanation here
14+ // an error occured because the variable str was already declared as a parameter of the function so
15+ // there was no need to use let again.
16+
617
18+ // =============> write your new code here
719function capitalise ( str ) {
8- let str = `${ str [ 0 ] . toUpperCase ( ) } ${ str . slice ( 1 ) } ` ;
20+ str = `${ str [ 0 ] . toUpperCase ( ) } ${ str . slice ( 1 ) } ` ;
921 return str ;
1022}
1123
12- // =============> write your explanation here
13- // =============> write your new code here
24+ console . log ( capitalise ( "hello" ) ) ;
Original file line number Diff line number Diff line change 1+ function capitaliseFirstLetter ( string ) {
2+ string = `${ string [ 0 ] . toUpperCase ( ) } ` ;
3+ return string ;
4+ }
5+
6+ console . log ( capitaliseFirstLetter ( "hello" ) ) ;
You can’t perform that action at this time.
0 commit comments