Pig Latin , unknown error

working for words with first letter vowel on console but test not passing and
for words without first alphabet not vowel it’s not working

let flag = 1;

function translatePigLatin(str) {

 

//console.log(str);

if(["a","e","i","o","u"].includes(str[0])){

//console.log(flag);

if(flag == 0){  

     return str+"ay";

}

else{

    return str+"way";

  }

}

else{

  flag = 0;

  translatePigLatin(str.slice(1,str.length)+str.slice(0,1));

} 

    }

translatePigLatin("consonant");

You’re calling the function within itself but the code isn’t running it because the function doesn’t return anything.
Try adding return at the beginning of this line. :slight_smile:

still not working for cases like translatePigLatin(“eight”),translatePigLatin(“rhythm”)

It passes all tests for me except rhythm. Your current code checks for the first vowel - how would you add a condition for a word with no vowels?

tried split and include, glove and eight not passing

 let flag = 1;
function translatePigLatin(str) {

  if(!str.split("").includes("a"||"e"||"i"||"o"||"u")){
    //console.log(str);
    return str+"ay";
  }
else{
//console.log(str);
if(["a","e","i","o","u"].includes(str[0])){
//console.log(flag);
if(flag == 0){  
     return str+"ay";
}
else{
    return str+"way";
  }
}

else{
  flag = 0;
  return translatePigLatin(str.slice(1,str.length)+str.slice(0,1));
} 
  }
   }

translatePigLatin("consonant");



Your split is returning “true” on those two.

but I used ! :thinking:

you can’t use "a" || "e" || "i" || "o" || "u"like that as argument of includes
try console.log("a" || "e" || "i" || "o" || "u") and see what you are actually checking