Pig Latin - Advanced Code Solution has an endless loop?

Hello,
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";
    else
        strArr = str.split("");

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

// test here
translatePigLatin("consonant");

I updated the code with the suggestion of @ilenia 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