Tell us what’s happening:
Hello!,
I’m stuck on pig latin challenge, I didn’t understand how to make the correct answer. I already pass 2 conditions, but the last condition I didn’t have an idea how to do that.
Your code so far
function translatePigLatin(str) {
let re1 = /^[aieuo]/;
let re2 = /[^aieuo]/;
if (re1.test(str)){
return str.concat('way');
} else if (re2.test(str)){
return str.concat('ay');
}
return str;
}
translatePigLatin("consonant");
Your browser information:
User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36.
I can completed paragraph word but when word is glove, i fail. because first two word isn’t vowel, if vowel in second position it pass.
How to take first letter until vowel letter?
You’d need a slightly different approach for this challenge. Instead of using .test() to check whether the first letter is a vowel or not, try finding the index of the first vowel instead (it could be 0, 1 or higher, depending on how many consonants come before it). One possible method would be using .match().
So, the first branch of the conditional matches the words beginning with vowels and handles them correctly. Since there are only two possibilities (begin with vowel or not), you only need an else for the second condition since you know it matches begin with consonant. You don’t even need the test. You can modify your consonant regular expression to match one or more consonants and then modify your string with replace() or other string functions. Remember, you have to rewrite the words so that consonant becomes onsonantcay or glove becomes oveglay (or “rest of word” + “first consonants” + “ay”).