Pig Latin Test Case is not passing


The last case is fails even the result is correct

:disappointed_relieved:


function translatePigLatin(str) {
  var pigLatin = '';
  var regex = /[aeiou]+/gi;
  if (str[0].match(regex)) {
    pigLatin = str + 'way';
  }else {
    var vowelIndex = str.indexOf(str.match(regex)[0]);
    pigLatin = str.substr(vowelIndex) + str.substr(0, vowelIndex) + 'ay';
  }
  return pigLatin;
}


translatePigLatin("consonant");

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.84 Safari/537.36.

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

Because of the last statement rule that is the without vowels.

How should I finish the last test?

Hey HooriaHic, Look my code and it’s successfully accepted.

function translatePigLatin(str) {
  return str.replace(/^([aeiou])(.*)/, '$1$2way').replace(/^([^aeiou]+)(.*)/, '$2$1ay');
}

translatePigLatin("consonant");     

Hope this helpful

1 Like

Thanks, SpadeX
:+1: your code is successfully accepted