translatePigLatin("rhythm")

My code fails on translatePigLatin(“rhythm”) test case

  • If a word begins with a consonant, take the first consonant or consonant cluster, move it to the end of the word, and add ay to it.

so translatePigLatin(“rhythm”); should be ythmrhay not rhythmay. Am I wrong?

Your code so far


function translatePigLatin(str) {
  if (str.match(/^[^aeioy]/)) {
    // consonant
    return str.replace(/^([^aeioy]*)(.*)/, "$2$1ay");
  }
  return str.replace(/^(.*)/, "$1way");
}

translatePigLatin("consonant");
  **Your browser information:**

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

Challenge: Pig Latin

Link to the challenge:

y isn’t a real vowel.

Should handle words without vowels. translatePigLatin("rhythm") should return the string rhythmay .

1 Like

Thanks. Googled and found this When Is 'Y' a Vowel or Consonant? | Merriam-Webster


Are they wrong too? Is there any “official” reference?

There are lots of minor variants of Pig Latin. Y doesn’t ‘act like’ a vowel when playing this version of Pig Latin.

1 Like

Understood. Thank you

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.