Pig Latin cannot understand what does it wants(if last is vowel condition)

Tell us what’s happening:

Your code so far

function translatePigLatin(str) {
    return str+"way";
  else if(str[str.length-1].match(/[aeiou]/)){
    var end1 = str[0]
    var end2 = str[1]
    str = str.substr(2)
    return str+end1+end2+"ay";
      var end = str[0]
      str = str.substr(1)
    return str+end+"ay"


Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36.

Link to the challenge:

I don’t see a condition about a word that neds in a vowel. Do you mean this?

If a word begins with a vowel you just add “way” to the end.

If a word starts with aeiou, like “eight”, “end”, “atom”, “island” etc, you just need to add “way” to the end of the word (“eigthway”, “endway”, “atomway”, “islandway” etcway)

The case when the string begins with a vowel looks fine.

However, you need to cover the major case. If the string begins with a consonant or a cluster of consonants, you need to move that consonant/cluster to the end with “ay”. One way to do this is to loop through the string (test whether the current character is a vowel) and whenever you find the first vowel, take whatever is to the left of it (you can use substring method) and move it to the end + “ay”. The loop will help you with your specific question as well (i.e. when the last character of the string is the first vowel, you just move all the characters to the right of the vowel, and the vowel becomes the first character).

Thanks for the response but the fact of the matter is that i am unable to understand the condition well i have applied all that i understand in this exercise and two condition clashes(i.e., 1st is the first word consonant and 2nd is the last word is a vowel) with each other and as a result the output is not as per the demand, maybe there is something i don’t understand

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

This condition is the one that is tested by the two tests:

Should handle words where the first vowel comes in the end of the word.

Should handle words without vowels.

It means that words like (and this are not all real words, just examples) “try”, that is a word without vowels, just have to becomes “tryay”, and a word like “bce” (vowel at the end of the word) have to becomes “ecbay”