Hi everyone,
Why is my Pig latin function not translating every word?
I have tried words with two consonants, two vowels, one consonant, one vowel, etc and most of them pass the tests but then some don’t, like “glove” and “eight”? Why?
Please don’t give me the code! Just point me in the right direction
thanks!!
function translatePigLatin(str) {
var vowels = ["a","e", "i", "o", "u", "A", "E", "I", "O", "U"];
var word = str.split("");
for (var i=0; i<vowels.length; i++) {
if (str.charAt(0) != vowels[i]){
if (str.indexOf(vowels[i]) == -1){
break;
}
var chunk = str.substring(0, str.indexOf(vowels[i]));
word.push(chunk, "ay");
word.splice(0, str.indexOf(vowels[i]));
str = word.join("");
} else {
word.push("way");
str = word.join("");
}
}
console.log(str);
return str;
}
translatePigLatin("crack");