Pig-latin 'Should handle words without vowels.'

Tell us what’s happening:
I can’t get the last test to pass: ‘Should handle words without vowels.’

The code I created worked in the original freeCodeCamp Pig Latin challenge, but does not work in the new one. I have tried three ways of handling words without vowels

  1. return the word without changing it (if the original word is ‘bcd’ return ‘bcd’)
  2. add ‘ay’ to the end of the word (if the original word is ‘bcd’ return ‘bcday’)
  3. move the first constant to the end of the word and add ‘ay’ (if the original word is ‘bcd’ return ‘cdbay’)

I have created code that successfully performs each of these options. You can see this code at CodePen.

I also tried the solutions in the certificate section of the freeCodeCamp guide for Pig Latin. None of those worked either, even after I inserted the missing opening bracket in both the Basic and Intermediate Code Solutions.

I am not sure what to try next. Any suggestions?


Your code so far

function translatePigLatin(str) {
  return /^[^aeyiuo]+$/.test(str) ?
    str :
//     str.replace(/^([^aeiouy])(.*)/, '$2$1ay') :
//     str + 'ay' :
      .replace(/^([aeiouy])(.*)/, '$1$2way')
      .replace(/^([^aeiouy]+)(.*)/, '$2$1ay');


Your browser information:

User Agent is: Mozilla/5.0 (X11; CrOS x86_64 10176.68.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.144 Safari/537.36.

Link to the challenge:

“y” isn’t a vowel.
Words without a vowel should still have “ay” added to the end.

Hint: here is the test

"assert.deepEqual(translatePigLatin(\"rhythm\"), \"rhythmay\", 'message: Should handle words without vowels.');"



Thank you. It usually turns out to be something obvious I am missing.

My final solution (that works) looks like this:

function translatePigLatin(str) {
    return str
      .replace(/^([aeiou])(.*)/, '$1$2way')
      .replace(/^([^aeiou]+)(.*)/, '$2$1ay');