Pig Latin [Algorithm Scripting] *SOLVED*

So i’m trying to do what the challenge says, moving the first consonants to the end of the string with an "ay" and it works but but i can’t find a way to apply this algorithm when it needs to move more than one consonant from the first.
ex :

translatePigLatin("glove") should return "oveglay".

this algo is only working for one letter to move to the end.
Can someone point out where i’m making any mistake.
Here is the code :


function translatePigLatin(str) {
  var arr = str.split("");
  var newStr="";
  for(let i=0;i<arr.length;i++){
    if(arr[i]==='a'||arr[i] === 'e'||arr[i] === 'i'||arr[i] === 'o'||arr[i] === 'u'){
    return str+"way";
  }else{
    newStr=str.substr(a[i]);
    return newStr+arr[i]+"ay";
  }
}
}
translatePigLatin("consonant");

Link to the challenge:


[@camperextraordinaire little help plz]

Now it says to handle words without vowels , But i guess i handled it at first test . right ?? then where is the problem now ?

My code : -------

function translatePigLatin(str) {
  var firstWord=str[0];
  var vowels=/[aeiou]/gi;
  var newStr="";
  if(!str.match(vowels)){
    return str;
  }
  if(firstWord.match(vowels)){
    newStr= str+'way';
  }else{
    var indexOfVowel=str.indexOf(str.match(vowels)[0]);
    newStr=str.substr(indexOfVowel)+str.substr(0,indexOfVowel)+'ay';
  }
  return newStr;
}

Oh damn it. im so stupid . i just have to add 'ay' to the end of str at :

if(!str.match(vowels)){
    return str+'ay';
  }

Now its done. pheewwww. thanks again :slight_smile: