Implement a Pig Latin Translator - Implement a Pig Latin Translator

Tell us what’s happening:

So I have been stuck at regexes lately. And i really wanna double down on coding, so I began returning to learning. BUT THIS REGEX! its correct (i think), but why aren’t the consonants appearing correctly before ‘ay’? Help would be appreciated!

Your code so far

function translatePigLatin(str) {
  const cons = /^[^aeiou]{1,}(?=[aeiou])/i;
  
  return str
    .replace(cons, '')
    + (str.match(cons)?.match == undefined ? '' : str.match(cons)[0])
    + (/^[aeiou]/i.test(str) ? 'w' : '') + 'ay'
}

console.log(translatePigLatin("paragraphs"))
console.log(translatePigLatin("schwartz"))

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36 Edg/142.0.0.0

Challenge Information:

Implement a Pig Latin Translator - Implement a Pig Latin Translator

It’s not your regular expression that’s an issue…it’s your logic at this line where the match is never concatenated.

And this is a great site to test and learn more about regular expressions: https://regex101.com/

I GOT IT!

I knew it was the faulty line, jus didn’t know what to do.. in the end i used a certain line of code we learn in the curriculum and it did the job!

1 Like