Pig Latin Challenge Last Test

Hello everybody,
my last test is not passing… I tried to cover it in the middle with my “else if” statement (commented out), but it corrupted the functionning part. Any idea how to fix this?

Here’s my code:

function translatePigLatin(str) {
  let vowelRegex = /^[aeiou]+/i;
  let noVowelRegex = /[^aeiou]+/i;
  if (vowelRegex.test(str)) {
    return str + "way";
 /* } else if (noVowelRegex.test(str)) {
      return str + "ay"; */
      } else {
       let consRegex = /^[^aeiou]+/i;
       let latinStr = str + str.match(consRegex) + "ay";
       latinStr = latinStr.replace(consRegex, "");
       return latinStr;
   } 
}
console.log(translatePigLatin("consonant"));

Thank you!

to make it easier to help you, please include challenge link and format your code correctly. You could use the Ask for help button and it would create a post with the challenge link and your code already included, you would then just need to write your question…


I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

Please use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks are not single quotes.

markdown_Forums

the issue is that your let noVowelRegex = /[^aeiou]+/i
this line will check if there is anything that is not a vowel, not if there are no vowels

to check if there are no vowels you need to use /[aeiou]/i and check if the test method returns false - in that case there are no vowels

Thank you very much, it works indeed.

or also /^[^aeiou]+$/i will work, to check that the string is all made of not-vowel characters. This would return true with the test method if there are no vowels