Pig Latin.33333

Can someone help with that , what’s wrong with my code ?

Your code so far

function translatePigLatin(str) {
  let aywa = str.search(/[aieou]/)
  let slt = str.split('')
    let spliced = slt.splice(0,aywa);
    return slt.join('');
  else if(aywa==0){
    return slt.join('');
    return str;


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:

For translatePigLatin(‘glove’), you function returns ‘oveg,lay’.

Part of the problem is:


Since spliced is an array [‘g’, ‘l’] in this test case, when you concatenate an array with a string like ‘ay’, JavaScript will convert the array to a string, so ['g','l'], becomes 'g,l' and then you add the 'ay' on the end, you end up with 'g,lay'. Since after the splice, slt is ‘ove’, your final join creates ‘oveg,lay’ which gets returned.

So i edited the return in the first if statment to this

return slt.join('').replace(/\W/g, '')

But i don’t know what the last condition wants, what should i do to words that have no vowels

For this, you will have to make a small change in this line:

Think of what could it be?

1 Like

The instructions (seen below) tell you what to do with such a word. If a word is all consonants, it is just one big consonant cluster which gets moved to the end and has ‘ay’ added on to it. So a word like rhythm becomes rhythmay.

Pig Latin takes the first consonant (or consonant cluster) of an English word, moves it to the end of the word and suffixes an “ay”

1 Like

right , so now that i have done it , could you comment on the way i wrote that code , what should i focus on later on