Tell us what’s happening:
I thought I had fixed it so it handled vowels, but then it didn’t pass, so I checked the console. And everything I’ve tried has put out wanted results!? Why do I not pass?
Please help I’m lost
Your code so far
function translatePigLatin(str) {
var firstVowel=str.match(/[aeuioy]/);
//Find first vowel in string
var firstPos=str.indexOf(firstVowel);
//Find position of first vowel in string
if(firstPos>0 && firstPos!=-1){
//If first vowel is not at 0, that means first letter of string will be a consonant.
//If there's a vowel in the string at all, that is to say
str=str.split("");
//Splits string letters into array elements for ease of manipulation
//Consciously breaking functional programming best practice for convenience
var mediator=str.splice(0,firstPos);
//Remove letters up until index of first vowel
str=str.concat(mediator);
//Add consonants that where removed in previous step to the end
str.push("ay");
//Add "ay" to end of array
str=str.join("");
//Turn str back into string
return str;
} else { //First index in string is a vowel, or there's no vowel
return str+="way";
//Add "way to the end"
}
console.log(str);
return str;//Manipulated string (str), dependent on first letter (||cluster of letters)
}
translatePigLatin("vaacndsnnt");
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36
.
Link to the challenge: