I wrote this code, it solved all except the word “glove” and I’m not sure why I need to make it return “oveglay” it starts with a consonant like the other words why I need to move the letter “L”? anyone can explain, please
function translatePigLatin(str) {
var vowel = [“a”, “e”, “i”, “o”, “u”];
var firstLetter = str.charAt(0);
if (vowel.indexOf(firstLetter) === -1) {
var newStr = str.split("");
var removed = newStr.splice(0, 1);
str = newStr.join("") + removed + "ay";
} else {
str = str + "way";
}
return str;
}
translatePigLatin(“glove”);
…