Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Write a function, nicknameGenerator that takes a string name as an argument and returns the first 3 or 4 letters as that name's nickname! If the 3rd letter is a vowel, return the first 4 letters.
- // Examples:
- // INPUT: nicknameGenerator('Daniel')
- // OUTPUT: 'Dan'
- // INPUT: nicknameGenerator('Beowulf')
- // OUTPUT: 'Beow'
- function nicknameGenerator(string) {
- var vowels = ['a', 'e', 'i', 'o', 'u'];
- if (string.length < 4) {
- return string;
- } else {
- if (vowels.includes(string[3])) {
- return string.slice(0,3);
- } else if (vowels.includes(string[4])) {
- return string.slice(0,4);
- }
- }
- }
- nicknameGenerator('dan')
Add Comment
Please, Sign In to add comment