Pig Latin word that don't have vowels

Tell us what’s happening:
from what I gathered on the forum posts if a word like rhythm is used, the y doesn’t count as a vowel. so you need to return the word plus way at the end. I tried to do that with the last else statement but it doesn’t pass the

Your code so far


function translatePigLatin(str) {
  let answer = '';
  let regex1 = /[a|i|e|o|u]/;
  if (str.startsWith('a') || str.startsWith('e') || str.startsWith('i') || str.startsWith('o') || str.startsWith('u')) {
    answer = str + "way";
  } else if(regex1.test(str)===true){
    let vowelIndex = str.indexOf(str.match(regex1)[0]);
    console.log(str.match(regex1));
    answer = str.substr(vowelIndex) + str.substr(0, vowelIndex) + 'ay';
    
  } else {
    answer = str + 'way'
  }
  return answer;
}

translatePigLatin("consonant");

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36.

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

I think it is the word plus ay so “my” becomes “myay”

1 Like

Words in bold will help you.

Pig Latin takes the first consonant (or consonant cluster) of an English word, moves it to the end of the word and suffixes an “ay”.