Pig Latin Algorithm - Words without vowels

Pig Latin Algorithm - Words without vowels
0

#1

Tell us what’s happening:

I’m working on Pig Latin Algorithm and have a problem with the final condition:
“Should handle words without vowels.”
First part of the code should handle the above, but the test won’t pass.
What am I doing wrong?

Your code so far


function translatePigLatin(str) {
  let tempStr = "";
  let counter = 0;
  // If str without vowels
  if((/^([^aeiouyAEIOUY0-9\W]+)$/).test(str)) {
    return str + "ay";
  }
  // Str has vowels & vowel is first
  if((/^[aeiouy]/).test(str)) {
    return str + "way";
  }
  // Str has vowels & consonant (cluster) is first
  if(!(/^[aeiouy]/).test(str)) {
    for(let i = 0; i < str.length; i++) {
      if(!(/[aeiouy]/).test(str[i])) {
        counter++;
      }
      else if((/[aeiouy]/).test(str[i])) {
        break;
      }
    }
    tempStr = str.substr(0, counter);
    str = str.substr(counter);
    str = str + tempStr + "ay";
    return str;
  }
}

translatePigLatin("xxx");

Your browser information:

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

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


#2

“Y” is considered a vowel in pig latin along with aeiou generally, however for this test only aeiou have been considered as vowel. I also came to know about this while doing this test. So simply add “ay” after aeiou, remove “y”.


#3

Solved the problem! Thank You!