Pig Latin_ error: Should handle words without vowels. But checked on ide it works

Pig Latin_ error: Should handle words without vowels. But checked on ide it works


Tell us what’s happening:
I am getting error as title says: Should handle words without vowels.
I have checked on different enviroment it gives correct output without vowels.
I am not sure where it is the mistake. Also if you can tell me how to improve my code I’d appreciate it .
thanks in advance
Your code so far

function translatePigLatin(str) {
  let index= 0;
  if (str[0]==="a"||str[0]==="i"||str[0]==="o"||str[0]==="y"||str[0]==="e"){
    return str+"way";
  else {
  for(let i of str){
    if(i === "a" || i === "i" || i === "o" || i === "y" || i === "e"){
  return str.slice(index)+str.slice(0,index)+"ay"

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36.

Link to the challenge:


does your code take a word like ‘my’ and give ‘myay’ ? That’s basically the requirement.


thanks for replying … Maybe I am not understanding the requirement. But,
should not be a “my” => “ymay”?
since on test “california” should return “aliforniacay” ??


I will not get into how to figure out how to deal with words with no vowels, but you could create an object containing the vowels like:

var vowels = {a: 1, e: 1, i: 1, o:1, u:1};

and then your 1st if statement would simply be:

if (vowels[str[0]]) {
  return str + "way";

You could also use the vowels object in your for loop also to simplify your if statement there too, but I will let you figure that part out.

Also, think about if you really even need that first if statement since you have a for loop checking all the letters in str anyway.


yeah, i understand the confusion but if you re-read the instructions, specifically this line:

Pig Latin takes the first consonant (or consonant cluster) of an English word, moves it to the end of the word and suffixes an “ay”.

you see they refer to “consonant cluster” Therefore “my” is a consonant cluster and needs to ‘move’ back
and therefore essentially stays the same.

There are other examples of how to handle consonant clusters here: