Pig Latin - algorithm doesn't handle words without vowels ... But it does!

Pig Latin - algorithm doesn't handle words without vowels ... But it does!
0

#1

Hello,
I have a problem with a task Intermediate Algorithm Scripting: Pig Latin.
It seems to me that all conditions are there to pass this task, but I still get the alert that my code doesn’t handl words without vowels.

I am not quite sure where is the problem.

**my code so far:

function translatePigLatin(str) {

const firstRegex = /^[aeiouy]/gi
const vowelsRegex = /[aeiouy]/gi

if(str.match(vowelsRegex) === null){
  str = str + "ay";
  return str;
} else if(!firstRegex.test(str)){
  const firstVowel = str.search(vowelsRegex);
  const ending = str.slice(firstVowel, str.length);
  const begin = str.slice(0, firstVowel);
  str = ending.concat(begin).concat("ay");
  return str;
}else{
str = str.concat("way");
return str
}
}

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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36.

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


#2

Make sure your algorithm handles the word rhythm. It should transform it into rhythmay and not ythmrhay as it is doing now.


#3

Thank you a lot. I made a stupid mistake. In Polish, “y” is also a vowel. That’s why I added it into my regex and eventually it was breaking my results.


#4

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 easier to read.

See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

Note: Backticks are not single quotes.