Pig Latin,Help, can anyone tell me what i am doing wrong?

Tell us what’s happening:
Help, can anyone tell me what i am doing wrong ? it returns correct answers but showing these two lines :
1.Should handle words where the first vowel comes in the end of the word.
2.Should handle words without vowels.

Your code so far

function translatePigLatin(str) {
if(str.match(/^[aeiou]/) && !str.match(/[aeiou]$/)){
 var a= str.split("");
 return a.join("");
else if(str.match(/[e]$/)){
  var firstTwo=str.replace(str.charAt(0),"").replace(str.charAt(1),"");
   var b=firstTwo.split("");
   return b.join("") ;
  var firstL=str.replace(str.charAt(0),"");
 var s= firstL.split("");
  return s.join("");


Your browser information:

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

Link to the challenge:

So when the test suite runs, there are a number of words that get run against your function. Here are some words you can use to get an idea what to expect:


So your function shouldn’t check the first letter, or the first two letters – instead, it should split the word just before the first vowel, regardless of how many consonants.

  • In the case of california, the word should split into c and alifornia
  • In the case of strength, it should split to str and ength
  • In the case of ache, it should split to an empty first string and ache (and if the first string is empty, simply change it to a w)
  • In the case of rhythm, the entire word is the first string and the second is empty

Hard-coding things like your firstTwo variable does doesn’t allow for words with more than two leading consonants. Instead, here are two other options to consider:

  1. create a for loop, run the length of the word. check the first character. If it’s a consonant, append that consonant to the end of a firstPart variable and remove it from the str. Loop doing this until the first vowel is encountered, then break out of the loop.
  2. use regex to find the indexOf the first vowel. Everything before that becomes firstPart.

Either of these approaches will allow you to build a string for the first part without explicitly limiting how many consonants it may contain.

thanks really appreciate your help.