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('')
  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

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