Pig Latin & RegEx help

Tell us what’s happening:
Describe your issue in detail here.

I would be grateful if someone could help me with the Pig Latin challenge.

It was passing the first 6 out of 7 criteria, but I had not considered words containing no vowels (i.e. “rhythm”).

I then went back and added lines 3 and 4 to account for this no-vowels scenario. But now I get the following error:
“TypeError: Cannot read property ‘join’ of null”

It must be something to do with lines 3 & 4. I’m sure it’s something quite simple but I can’t seem to figure it out.

I’m still quite new to coding and it’s probably something basic. But would appreciate some help.

Thank you

  **Your code so far**

function translatePigLatin(str) {
// if string contains no vowels
 if (str.match(/[aeiou]/i) == false) {
    return str + "ay"

// else if string starts with consonants
  } else if (str.match(/^[^aeiou]+/i)) {
  var newSuffix = str.match(/^[^aeiou]+/i);
  var newPrefix = str.match(/[aeiou]+[\w]*$/i);
  return newPrefix.join() + newSuffix.join() + "ay";

  // else string starts with vowels
} else {
  return str.concat("way")


  **Your browser information:**

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

Challenge: Pig Latin

Link to the challenge:

Spoke too soon. I found a solution. I changed line 3 to:
if (str.match(/^[^aeiou]+$/i)) {

I’m still not sure why my previous approach did not work. I’d be grateful if someone could point out my error.

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