Pig Latin - SOLVED;NO HELP NEEDED

Pig Latin - SOLVED;NO HELP NEEDED
0

#1

Tell us what’s happening:
Can’t see what the last criteria means… :expressionless:

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){
    //If first vowel is not at 0, that means first letter of string will be a consonant.
 
  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 if (firstPos===-1) {
    //I thought the syntax above meant (if) there was no match for the indexOf function?
    //Added this else if statement even though it's redundant because I can't figure out the last criteria
  return str+="way";
  } else { //First index in string is a vowel
    return str+="way";
    //Add "way to the end"
}
return str;//Manipulated string (str), dependent on first letter (||cluster of letters)
}

translatePigLatin("cnsnnt");

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

Sorry, found someone else explain it:

The test Should handle words without vowels. means that your code should work when you get words without vowels. I quickly did a test with your code and if I would take the non existent word: pkljdsk, in pig latin this would be pkljdskay but if I use your code, I get kpkljdsay. Your first letter is wrong.

Edit: This is because they say consonant or consonant cluster, so your full word is one cluster and moves to the back => stays the same. Currently one letter is moved.