Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sethschori/6cabf086ee2ff1907370b972c7a8fabd to your computer and use it in GitHub Desktop.
Save sethschori/6cabf086ee2ff1907370b972c7a8fabd to your computer and use it in GitHub Desktop.
https://repl.it/C80f/12 created by sethopia
/*
NICKNAME GENERATOR
Write a naive nickname generator function that takes a name and returns the first 3 or 4 letters (4 letters if the 3rd is a vowel)
eg nickName("daniel") ==> 'dan'
nickName("Beowulf") ==> 'Beow'
*/
function nickName(name) {
if (name.charAt(2).toLowerCase() === "a" || name.charAt(2).toLowerCase() === "e" || name.charAt(2).toLowerCase() === "i" || name.charAt(2).toLowerCase() === "o" || name.charAt(2).toLowerCase() === "u") {
return name.slice(0,4);
} else {
return name.slice(0,3);
}
}
console.log(nickName("daniel"));
console.log(nickName("Beowulf"));
Native Browser JavaScript
>>> dan
Beow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment