Pig Latin challenge mysteriously sometimes passes and sometimes doesn't

Hello all,
Can someone please guide me in the right direction? I’m assuming that there’s a much better way to solve this challenge but I’m having a hard time seeing why my way of thinking won’t pass the challenge. Or more strangely, when I run the tests for my code, sometimes it passes the challenge and sometimes my code doesn’t pass the “should handle words without vowels” requirement. I am assuming that if a string composed without any vowels is passed into the function, that the function merely repeats the vowel-less string and attaches an “-ay” to the end and so that’s why I ended the code with "return str + “ay”. Thanks for any guidance and hope you’re enjoying your day!

function translatePigLatin(str) {
  let strArr = [...str];
  
  if (strArr[0] === "a"||strArr[0] === "e"||strArr[0] === "i"||strArr [0] === "o"||strArr[0] === "u"){
    return strArr.join("")+ "way";
  
  }else {
    while (strArr[0]!= "a" && strArr[0]!= "e" && strArr[0]!= "i" && strArr[0]!= "o" && strArr[0]!= "u"){
      
      
      let firstCons = strArr.shift();
      strArr.push(firstCons);

    }return strArr.join("")+"ay"
  }
    return str + "ay"

}
translatePigLatin("bcdfg");

There’s a problem with the logic you picked for this challenge.

Your while loop will go through each letter and then reverse them no matter what.

That’s not what you want to achieve because…

What about words that do not contain any vowel?

To get that beautiful green window, words that do not contain any vowel should be kept as they are and the difference is to only add an ay suffix to them.

1 Like

I appreciate the response!

You’re welcome.

Good Luck & Happy Coding!