Intermediate Algorithm Scripting - Pig Latin

Tell us what’s happening:
Describe your issue in detail here.
I spent five hours trying to figure out what the problem is, pls, someone should look into my code and tell me what is wrong
Your code so far

function translatePigLatin(str) {
  let vowel = /[aeiou]gi/;
  let pigLatin = "";
  if (str[0].match(vowel)) {
    pigLatin = str + "way";
  } else if 
    (str.match(vowel) === null) {
pigLatin = str + "ay"
    } else {
      let firstVowel = str.indexOf(str.match(vowel)[0]);
      pigLatin = str.substr(firstVowel) + str.substr(0, firstVowel) + "ay"
    }
  return pigLatin
}

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

Your browser information:

User Agent is: Mozilla/5.0 (Linux; Android 11; TECNO LE6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.98 Mobile Safari/537.36

Challenge: Intermediate Algorithm Scripting - Pig Latin

Link to the challenge:

Are you sure that’s the pattern you want to match for?

1 Like

Sure. Did u figure out where my mistake comes from?

Yes, I think I gave you a big hint with the question I asked you :slightly_smiling_face:

/[aeiou]gi/;

What are you using gi for? Are you sure it is in the correct place?

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