Pig Latin. Need help for Glove case

Tell us what’s happening:

So I’m doing this challenge and i have trouble finding out how to get the test case glove right, how do you code it to include both ‘gl’ instead of just ‘g’ to pushed into the back?

Your code so far


function translatePigLatin(str) {
  let word = str;
  const firstLetter = str.split('')[0];
  let newWord = '';
  
  //check if first letter is consonant
  function isConsonant() {
    return /[aeiou]/.test(firstLetter)
  }
  
  if(isConsonant() === false) {
    newWord = word.substring(1).concat(`${firstLetter}ay`);
    return newWord;
  } else {
    newWord = word.concat(`way`);
    return newWord;
  }
  return newWord
}


translatePigLatin("aonsonant")

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.100 Safari/537.36.

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

You may use regex to search consonants. Consider words as glove, three. At least one consonant.

Determining if the first letter is a consonant will not give you enough information to perform the required task. There could be another consonant after it, like in the “glove” example, or there could be 15 of them in a row. You just don’t know. What if, instead, you try to find where the first vowel is?

1 Like

I did not think of that… Thank you! It does make sense trying to find the first vowel.