Skip to content

Commit db7592c

Browse files
committed
answer for initials.js with comments
1 parent f428d25 commit db7592c

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

Sprint-1/1-key-exercises/2-initials.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@ let lastName = "Johnson";
55
// Declare a variable called initials that stores the first character of each string.
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

8-
let initials =`${firstName.charAt(0)}${middleName.charAt(0)}${lastName.charAt(0)}`;
8+
//Answer:
9+
//Solution using charAt() a Javascript string method that returns a character's position, using template literal
10+
// and toUpperCase to ensure it is capitalized.
11+
let initials = `${firstName.charAt(0)}${middleName.charAt(0)}${lastName.charAt(0)}`.toUpperCase();
12+
13+
14+
//alternative solution using string indexing, template literal and toUppercase(to make sure it is capitalized)
15+
//let initials - `${firstName[0]}${middleName[0]}${lastName[0]}`.toUpperCase());
916

1017
// https://www.google.com/search?q=get+first+character+of+string+mdn
1118

0 commit comments

Comments
 (0)