Pig Latin - Advanced Code Solution has an endless loop?

As I started to write this, I have been suggested that this topic has been addressed before but I believe the solution/challenge has not been updated for the same.

   var strArr = [];
    var tmpChar;

    // check if the char is consonant using RegEx
    function isConsonant(char) {
        return !/[aeiou]/.test(char);

    // return initial str + "way" if it starts with vowel
    // if not - convert str to array
    if (!isConsonant(str.charAt(0)))
        return str + "way";
        strArr = str.split("");

    // push all consonats to the end of the array
    while (isConsonant(strArr[0])) {
        tmpChar = strArr.shift();
 // convert array to string and concatenate "ay" at the end  
 return strArr.join("")+"ay";

// test here

I updated the code with the suggestion of @ieahleen to pass the challenge.

if ( isConsonant (str)) {
** return str + “ay”; }**

Kindly correct me if I’m wrong but I was not able to pass the (SHOULD HANDLE WORDS WITHOUT VOWELS) check otherwise.

Thank you for everything you guys do <3

The Guide is in the process of being moved, so the old Guide isn’t going to show changes.

1 Like