Pig Latin | Error?

Tell us what’s happening:

Everything is going to pass except: Should handle words where the first vowel comes in the end of the word.
But when I pass eight. I get eightway. The same with algorithm.

Your code so far

function translatePigLatin(str) {
  let split = str.split("");
  let vocals = ["a","e","i","o","u"];
  let i = 0;

    while (split.indexOf(vocals[i]) < 0){

  let rest = str.substring(0,i+1);
  let leftovers = str.substring(i+1);
  for (let j = 0; j < split.length; j++){
    if (split.indexOf(vocals[j]) === 0){
        return str + "way";

  return leftovers + rest + "ay";


Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:62.0) Gecko/20100101 Firefox/62.0.

Link to the challenge:

I opened up the thread too quickly. Sorry for that! I see the problem now!

Please provide your solution (marked with spoiler tags)

This text will be blurred

function translatePigLatin(str) {
let regex = str.match(/[aeiou]/);
let firstVowel = str.indexOf(regex);

if(firstVowel >0){
return str.splice(firstVowel) + str.slice(0,firstVowel) +“ay”;
else if(firstVowel <0){
return str+“way”;

return str + “way”;