Yes, I thought so. So then I check the following:
if(firstLetters.match(/[aeiou]/) === null && (/[aeiou]/).test(str[str.length-1]) === true) {
return true; }
I believe that this checks if there is a vowel in the word not including the last character:
if(firstLetters.match(/[aeiou]/) === null
And this checks if the last character is a vowel:
&& (/[aeiou]/).test(str[str.length-1]) === true) // Maybe my error is here?
My problem is that I am not passing one condition of the algorithm which is:
“Should handle words where the first vowel comes in the end of the word.”
The actual function includes a different return statement. This is for the PigLatin algorithm -
" 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”.
If a word begins with a vowel you just add “way” to the end.
Input strings are guaranteed to be English words in all lowercase."
Here is my actual function:
function translatePigLatin(str) {
let firstLetters = str.split("").slice(0,str.length-1).join("");
if(firstLetters.match(/[aeiou]/) === null && (/[aeiou]/).test(str[str.length-1]) === true){var answer = str[str.length-1].concat(firstLetters).concat("ay")}
return answer;
}
Maybe there is an issue with how I define var answer?