Tell us what’s happening:
Can’t see what the last criteria means…
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){
//If first vowel is not at 0, that means first letter of string will be a consonant.
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 if (firstPos===-1) {
//I thought the syntax above meant (if) there was no match for the indexOf function?
//Added this else if statement even though it's redundant because I can't figure out the last criteria
return str+="way";
} else { //First index in string is a vowel
return str+="way";
//Add "way to the end"
}
return str;//Manipulated string (str), dependent on first letter (||cluster of letters)
}
translatePigLatin("cnsnnt");
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: