Pig Latin- last case not passing

The last case fails even though result is correct.

Your code so far

function translatePigLatin(str) {
  var firstVowel = str.match(/[aeiou]/);
  var firstPosition = str.indexOf(firstVowel);

  if (firstPosition > 0) {
    return str.slice(firstPosition) + str.slice(0, firstPosition) + 'ay';
  return str + 'way';


Your browser information:

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

Link to the challenge:

You should add ‘ay’ to the word, if there is no vowel. But you are adding ‘way’ even to the words with no vowels.

1 Like

if there is no vowels indexOf returns -1

cant seem to find a way to satisfy both conditions >0 || < 0 without breaking this code

alright solved using adding method simiilar to basic code solution … thanks :smiley: