Tell us what’s happening:
I am having trouble determining why when a user submits a word that does not contain any vowels into my function, the same string is returned rather that the string + “ay”.
Your code so far
function translatePigLatin(str) {
let regex = /^[aeiou]/;
let noVowelRegex = /[aeiou]/g;
if (!regex.test(str)){
str = str.replace(/([^aeiou]+)([aeiou]\w+)/, "$2$1ay");
}else if (regex.test(str)){
str = str + "way";
}else if (str.match(noVowelRegex) == null){
str = str + "ay";
} return str;
}
console.log(translatePigLatin("lynx"));
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36
Challenge: Intermediate Algorithm Scripting - Pig Latin
Link to the challenge: