Should handle words without vowels: Pig Latin

Tell us what’s happening:

Hello guys, my code for this exercise mostly works (despite being a bit hard to read) but it isn’t passing the last test regarding words without vowels. I ran it in repl.it and it came out with an output of ‘cnpltay’. Is there anything I’m doing incorrectly? Thank!

Your code so far


function translatePigLatin(str) {
  if (str.match(/[aeiouy*]/)=='') return str + "ay";
  if (str.match(/^[aeiouy]/)) str += "way";
  else str = str + str.match(/^\w+?(?=[aeiouy])/) + "ay"; 
  while (str.match(/^[aeiouy]/)==null) {
  str = str.split("").splice(1).join("");
  }

  return str;
}

translatePigLatin("cmnplt");

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36.

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

Hello Randall,

Thank for the help!
I made the first if statement so that if the input was purely consonants then it would go through that first, but I did not think that it would have to be set equal to null and ‘’. Thanks for helping me find where my error was.