Pig Latin Algorithm: Help with Regex

Tell us what’s happening:

All tests are passing, except the last, which tests if the code works with a string of all consonants. I thought my last ‘else if’ code would have taken care of that, but it did not. Any help is appreciated, thanks!

Your code so far

function translatePigLatin(str) {
 let vowel = str.search(/[ueoaiy]/);
 let allConsonants = /^[^aeiou]+$/i;
  if (vowel == 0) {
    return str + 'way';
  } else if (vowel !== 0) {
     return str.substr(vowel) + str.substr(0, vowel) + 'ay';
  } else if (allConsonants.test(str)) {
    return str + 'ay';


Link to the challenge:

I think you meant the test that says “Should handle words without vowels.” A word like rhythm would be such a word.

Your code returns ‘ythmrhay’ for ‘rhythm’ when it should return '‘rhythmay’

Hint: ‘y’ is not considered a vowel.

1 Like

Thanks, I used your suggestion. I also moved the last ‘else if’ to the first ‘else if’ and it worked (the order of operations was also throwing the code off).