Tell us what’s happening:
Can someone tell me why this does not work.
The first part passes but the second fails.
Your code so far
function translatePigLatin(str) {
let vowels = ['a', 'e', 'i', 'o', 'u'];
let newStr = "";
if(vowels.indexOf(vowels[0]) > -1) {
newStr = str + "way";
return newStr
} else {
let firstMatch = str.match(/[aeiou]/g) || 0;
let vowel = str.indexOf(firstMatch[0]);
newStr = str.substring(vowel) + str.substring(0, vowel) + "ay";
return newStr;
}
translatePigLatin("consonant");
Challenge: Pig Latin
Link to the challenge: