File tree Expand file tree Collapse file tree 1 file changed +17
-9
lines changed
Expand file tree Collapse file tree 1 file changed +17
-9
lines changed Original file line number Diff line number Diff line change 1- "hello Mhairi" === `hello ${ mhairiName } ` ;
2- "${mhairiName} is 28" === `Mhairi is ${ mhairiAge } ` ;
1+ // Predict and explain first...
2+ // it should show syntax error
33
4- // My answer is:
5- const mhairiName = "Mhairi" ;
6- const mhairiAge = 28 ;
4+ // call the function capitalise with a string input
5+ // interpret the error message and figure out why an error is occurring
76
8- const sentence1 = `Hello ${ mhairiName } ,nice to meet you` ;
9- console . log ( sentence1 ) ; // ➜ Output: Hello Mhairi, nice to meet you
7+ function capitalise ( str ) {
8+ let str = `${ str [ 0 ] . toUpperCase ( ) } ${ str . slice ( 1 ) } ` ;
9+ return str ;
10+ }
11+
12+ // the input "sty" is the same as output "str" which is not allowed in JS
13+ // my new code:
14+
15+ function capitalise ( str ) {
16+ return ( `${ str [ 0 ] . toUpperCase ( ) } ${ str . slice ( 1 ) } ` )
17+ }
18+ console . log ( capitalise ( "morning" ) )
19+ console . log ( capitalise ( "heavy" ) )
1020
1121
12- const sentence = `${ mhairiName } is ${ mhairiAge } years old` ;
13- console . log ( sentence ) ; // ➜ Output: Mhairi is 28 years old
You can’t perform that action at this time.
0 commit comments