Here’s the link to the challenge:
Here’s my code:
function translatePigLatin(str) {
var firstVowel = str.match(/[aeiou]/);
var firstPosition = str.indexOf(firstVowel);
if (firstPosition > 0) {
return str.substring(firstPosition) + str.substring(0, firstPosition) + "ay";
} else {
return str + "way";
}
}
I’m unable to pass the final test case:
“Should handle words without vowels. translatePigLatin("rhythm")
should return the string rhythmay
.”
Could anyone please advise what I’m doing wrong here?