Pig Latin.33333

Pig Latin.33333
0

#1

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('')
  if(aywa>0){
    let spliced = slt.splice(0,aywa);
    slt.push(spliced+'ay');
    return slt.join('');
  }
  else if(aywa==0){
    slt.push('way');
    return slt.join('');
  }
  else{
    return str;
  }
}

translatePigLatin("consonant");

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


#2

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

Part of the problem is:

slt.push(spliced+'ay');

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.


#3

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


#4

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

Think of what could it be?


#5

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”


#6

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