Tell us what’s happening:
Sorry in advance if my code looks terrible, but what I’ve come up with seems to get the right returns, but the challenge doesn’t seem to accept it. I can only pass the “word starts with a vowel” parts of the challenge (with the words “algorithm” and “eight”), but I should be passing the rest, as far as I can tell. At the bottom of my code I included the 5 test cases provided, as well as two I made up for the other requirements- one that has a vowel at the very end of a word (which is just a bunch of L’s with an A at the end of it) and one that is just some random consonants. I can’t tell what would be the reason that it’s not working, so any help would be greatly appreciated.
Your code so far
function translatePigLatin(str) {
let tempStr = str.split('');
if (tempStr[0].match(/[aeiou]/) || str.match(/[^aeiou]+/) == str) {
tempStr.push('way');
return tempStr.join('');
} else {
for (let i=0; i < tempStr.length; i++) {
if (tempStr[i].match(/[^aeiou]/)) {
tempStr.push(tempStr[i]);
} else {
tempStr.push('ay');
break
}
}
}
let finalStr = tempStr.join('');
return finalStr.match(/[aeoiu]+[\w]+/);
}
console.log(translatePigLatin("california"));
console.log(translatePigLatin("paragraphs"));
console.log(translatePigLatin("glove"));
console.log(translatePigLatin("algorithm"));
console.log(translatePigLatin('eight'));
console.log('')
console.log(translatePigLatin('llllllllla'));
console.log(translatePigLatin('jklmnp'));
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.157 Safari/537.36
.
Link to the challenge: