Pig Latin First Vowel Comes at the End

Tell us what’s happening:
I made some code that is passing all the checks except for this one:

“Should handle words where the first vowel comes in the end of the word.”

I’ve tested it with the word “the” and I get “ethay”, which I believe is correct. Does anyone know what specifically this check is looking for?

Your code so far


function translatePigLatin(str) {
	var arr = str;
  switch (arr[0]) {
    case 'a':
    case 'e':
    case 'i':
    case 'o':
    case 'u':
      return arr.concat("way");
      break
    default:
    	var match = arr.match(/^[bcdfghjklmnpqrstv]*(?=[aeiou])/i);
    	if (match != undefined) {arr = arr.replace(match[0],'');return arr.concat(match[0] + "ay")}else{return arr.concat("ay")}
    	break;
  }
}

console.log(translatePigLatin("the"));

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/pig-latin

I copied your code and like you say, it didn’t pass. I changed the line with the regex and it passed.

The line with the regex is not complete. you’re missing the ‘w - z’.

However, there is a better way/shorter way to write the regex you want.
Consider the regex /[^abc]/. This looks for any character that isn’t a, b or c.

1 Like

I totally missed that I didn’t have all the letters, and I changed it out with /[^aeiou]/, and it worked. Thanks so much for the help!

No problem. Glad to be of help!