-
-
Save sethschori/6cabf086ee2ff1907370b972c7a8fabd to your computer and use it in GitHub Desktop.
https://repl.it/C80f/12 created by sethopia
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Native Browser JavaScript | |
>>> dan | |
Beow |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment