Pig Latin - WHAT!?

Pig Latin - WHAT!?
0

#1

Tell us what’s happening:
I thought I had fixed it so it handled vowels, but then it didn’t pass, so I checked the console. And everything I’ve tried has put out wanted results!? Why do I not pass?

Please help I’m lost

Your code so far


function translatePigLatin(str) {
  var firstVowel=str.match(/[aeuioy]/); 
  //Find first vowel in string

  var firstPos=str.indexOf(firstVowel);
  //Find position of first vowel in string
 
  if(firstPos>0 && firstPos!=-1){
    //If first vowel is not at 0, that means first letter of string will be a consonant.
    //If there's a vowel in the string at all, that is to say
  str=str.split(""); 
  //Splits string letters into array elements for ease of manipulation
  //Consciously breaking functional programming best practice for convenience
  
  var mediator=str.splice(0,firstPos);
  //Remove letters up until index of first vowel
  
  str=str.concat(mediator);
  //Add consonants that where removed in previous step to the end
  
  str.push("ay");
  //Add "ay" to end of array
  
  str=str.join("");
  //Turn str back into string 
  return str;

  } else { //First index in string is a vowel, or there's no vowel
    return str+="way";
    //Add "way to the end"
}
  console.log(str);
return str;//Manipulated string (str), dependent on first letter (||cluster of letters)
}

translatePigLatin("vaacndsnnt");


Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36.

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


#2

not quite working…
your output for this string ‘my’ is ‘ymay’ but it should instead give ‘myay’


#3

Is m not a consonant? :joy:


#4

Appreciate the help, I don’t see why that is wrong though?
It removes m from beginning, puts it last, then adds ay. Is that not correct? What am I missing?


#5

Here is where a search of the forum would have helped you. You would have found many others making a similar assumption.
The reason the assumption is wrong is the following instruction from the challenge:

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”.

Notice they said consonant cluster ? In the case of ‘my’ , the whole word ‘my’ is a consonant cluster. So the whole thing is treated as one block. Other example:

‘block’ starts with the consonant cluster ‘bl’ so they are treated as one block and it becomes ‘ockblay’
‘try’ starts with the consonant cluster ‘try’ so we end up with ‘tryay’


#6

‘Y’ is a consonant, so ‘my’ is a consonant cluster.


#7

Look at my answer to Ariel


#8

Didn’t know that :grimacing::rofl:

But when I lose the Y, I don’t pass either!


#9

I didn’t understand your response to Ariel.

It is a simple matter. If your word doesn’t have any vowels, then simply append ‘ay’ to the end and return the result.


#10

Ahaa! There you go, now I understand, thank you!


#11

i just noticed this. The english vowels are a, e, i, o, u (5 of them, no ‘y’).
Just fyi.


#12

Yeah thank you!.,.-.