Code examples
There's a task to write a function, that takes a name as an argument and returns the first 3 or 4 letters as a nickname (if the 3rd letter is a vowel, return the first 4 letters)
function nicknameGenerator(name) {
if (name.length < 4) {
return 'Error: Name too short'
}
let vowels = ['e','u','i','o','a']
for (let i = 0; i < vowels.length; i++) {
if (name[2] === vowels[i]) {
return name.slice(0, 4)
}
}
return name.slice(0,3)
}