Skip to content

Instantly share code, notes, and snippets.

Created July 31, 2016 17:02
Show Gist options
  • Save anonymous/923b40f3f60407a1b667448f38723631 to your computer and use it in GitHub Desktop.
Save anonymous/923b40f3f60407a1b667448f38723631 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