Pig Latin Test Case is not passing

Pig Latin Test Case is not passing
0

#1

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


#2

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


#5

How should I finish the last test?


#6

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


#7

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