Tell us what’s happening:
Describe your issue in detail here:
I’m trying to find a way if I can create a function to solve this problem.
I have checked all the requirements except the last one:
[[Should handle words without vowels. translatePigLatin("rhythm")
should return the string rhythmay
.]]
I can’t seem to find a way to meet this condition, any tips??
**Your code so far**
function translatePigLatin(str) {
let vowelPosition = findFirstVowel(str);
return vowelPosition > 0
? str.slice(vowelPosition) + str.slice(0, vowelPosition) + "ay"
: vowelPosition === - 1
? str + "ay"
: str + "way";
function findFirstVowel(str) {
for(let i = 0; i < str.length; i++) {
if(["a", "e", "i", "o", "u"].includes(str[i])) return i;
}
}
}
console.log(translatePigLatin("california"));
**Your browser information:**
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36
Challenge: Pig Latin
Link to the challenge: