Issue:
Can some please explain why this code block does not pass the challenge, the last test “Should handle words without vowels.”, But I believe I handle it correctly in the first if statement. Please correct me, and advise what is the mistake in my code
My code so far
function translatePigLatin(str) {
if (!str.match(/[aeiou]/g)) {
str = str.replace(/([\w])([\w]+)/g, "$2$1ay");
} else if (str.match(/^[aeiou]\w+/)) {
str = str.replace(/(^[aeiou])(\w+)/, "$1$2way");
} else if (str.match(/^[^aeiou][^aeiou]+/)) {
str = str.replace(/(^[^aeiou][^aeiou]+)(\w+)/, "$2$1ay");
} else {
str = str.replace(/(^[^aeiou])(\w+)/, "$2$1ay");
}
return str;
}
// test here
translatePigLatin("consonant");