Pig Latin Can't find mistake

Pig Latin Can't find mistake
0

It failed and I don’t know why.

Your code so far


function translatePigLatin(str) {
  var letters = str.split("");
  var vowelRegex = /[aeiou]/gi;
  if (vowelRegex.test(letters[0])) {
    return letters.join("") + "way";
  }
  while (true) {
    if (!vowelRegex.test(letters[0])) {
      letters.push(letters.splice(0, 1));
    }
    else {
      break;
    }
  }
  str = letters.join("") + "ay";

  return str;
}

translatePigLatin("consonant");

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:68.0) Gecko/20100101 Firefox/68.0.

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

 while (true) {
    if (!vowelRegex.test(letters[0])) {
      letters.push(letters.splice(0, 1));
    }
    else {
      break;
    }
  }

This creates an infinite loop. If FCC didn’t use a timeout safety feature, it would crash your browser.