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';
  }
}

translatePigLatin("california")


Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/pig-latin/

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).