Turn a full name into its initials.
What to build
A program that takes one letter from each word of a line.
Requirements
- Read a full name.
- Take the first character of each word and make it upper case.
- Print each one followed by a dot, with no spaces.
Input
One line of words separated by single spaces.
Output
One line of initials, as in the example.
Constraints
The line has from 1 to 10 words, each starting with a letter.
Example
Input:
mitu akter
Output:
M.A.
Why it works
split breaks the problem into one word at a time. Upper-casing only the first character is enough, and because strings never change, the result is built up in a new variable.
Examples
Example 1 · Input
mitu akter
Expected output
M.A.
Example 2 · Input
Abdullah al Mamun
Expected output
A.A.M.
Hints
Hint 1
split(" ") gives the separate words.
Hint 2
word[0] is the first character of a word.
Hint 3
Build the answer with a loop, adding the letter and a dot each time.
Solution
Show one correct solution (try it yourself first)
const words = prompt().split(" ");
let initials = "";
for (const word of words) {
initials += word[0].toUpperCase() + ".";
}
console.log(initials);