Pig Latin: what should i do so that it can handle words without vowels

Pig Latin: what should i do so that it can handle words without vowels
0.0 0

#1

Tell us what’s happening:

Your code so far


function translatePigLatin(str) {
   var pigLatin = '';
  var regex = /[aeiou]/gi;

  // Check if the first character is a vowel
  if (str[0].match(regex)) {
    pigLatin = str + 'way';

  
  } else if(regex.test(str)) {
    let x = str.match(regex)
    pigLatin = str.substr(str.indexOf(x[0]),str.length)+str.substr(0,str.indexOf(x[0]))+"ay"
  }else{
    pigLatin = str.substr(1,str.length)+str.substr(0,1)+"ay"
  }

  return pigLatin;
}

translatePigLatin("consonant");

Your browser information:

User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/pig-latin
what should i do so that it can handle words without vowels


#2

I believe just return the exact same word plus ay

My -> myay