Intermediate Algorithm Scripting: Pig Latin 56565

Tell us what’s happening:
hello it seems im having trouble getting the last if statement right in order to pass the ‘Should handle words where the first vowel comes in the end of the word.’. Is something wrong with my code, because it doesnt clarify what must be returned in this case.
Thanx in advance

Your code so far


function translatePigLatin(str) {
  var regexx = /a|i|o|e|u/g;
  var aa = str.split('');
  var bb = str.slice();
  var n = str.length; 
  
  if (str[0].match(regexx)) {
    return str.concat('way');
  }

  if (str.match(regexx) == null) {
    return str.concat('ay');
  }

  if (str[0].match(regexx) == null && str[1].match(regexx)) {
    aa.shift();
    aa.push(bb[0]);
    let k = aa.join('');
    return k.concat('ay');
  }

  if (str[0].match(regexx) == null && str[1].match(regexx) == null) {
    aa.shift();
    aa.shift();
    aa.push(bb[0]);
    aa.push(bb[1]);
    let k = aa.join('');
    return k.concat('ay');
  } 

  let checkk = str.slice(0,n-1);
  console.log(checkk);
  if (str[n-1].match(regexx) && checkk.match(regexx) == null) {
    let rr = str[n-1].concat(checkk);
    console.log(rr);
    let gg = rr.concat('ay');
    console.log(gg);
    return gg;
  } 
 
}

translatePigLatin("ttko");


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

How does your function handle words like “school” or “schwartz”? You current solution should be able to handle words with vowels which are in any position of the word. You only handle cases where the vowel is the first, second, or last character. You are trying to “hard-code” the various cases, but you should be looking for a more generic solution which does not depend on you writing code for each possible position a vowel could be in a word.

thank you for the quick response ill work it out again with a generic solution like you said.