@@ -6,9 +6,27 @@ let lastName = "Johnson";
66// This should produce the string "CKJ", but you must not write the characters C, K, or J in the code of your solution.
77
88
9- // let initials = `${firstName.slice(0,1)}${middleName.slice(0,1)}${lastName.slice(0,1)}`;
10- let initials = `${ firstName . charAt ( 0 ) } ${ middleName . charAt ( 0 ) } ${ lastName . charAt ( 0 ) } ` ;
9+ // let initials = `${firstName.slice(0,1)}${middleName.slice(0,1)}${lastName.slice(0,1)}`; using slice on template literals
10+
11+ //let initials = `${firstName.charAt(0)}${middleName.charAt(0)}${lastName.charAt(0)}`; using charAt on template literals
12+
13+ //let initials = (firstName[0] || '') + (middleName[0] || '') + (lastName[0] || ''); using concatenation
14+
15+ // let initials = `${firstName[0] || ''}${middleName[0] || ''}${lastName[0] || ''}` //template literals
16+
17+ //let initials = [firstName, middleName, lastName].map(name => name.slice(0,1)).join('')
18+
19+ let initials = [ firstName , middleName , lastName ] . map ( name => name . charAt ( 0 ) ) . join ( '' )
20+
21+ /*
22+ There are more efficient ways of implementing the solution, however these concepts haven't been covered yet
23+ In these scenarios the slice and charAt have been implemented through a map
24+
25+ let initials = [firstName, middleName, lastName].map(name => name.slice(0,1)).join('')
26+ let initials = [firstName, middleName, lastName].map(name => name.charAt(0)).join('')
27+
28+ */
1129
1230// https://www.google.com/search?q=get+first+character+of+string+mdn
1331
14- console . log ( initials ) ;
32+ console . log ( initials ) ; // display the output of initials to verify if successfuly executed
0 commit comments