Does this regex condition make sense?

I want to check if the first vowel of a string comes at the end of the string. If so the function should return true.

function checkForVowel(str) {

let firstLetters = str.split("").slice(0,str.length-1).join("");

if(firstLetters.match(/[aeiou]/) === null & (/[aeiou]/).test(str[str.length-1]) === true) {
return true; }

}

you are checking the first and last letter, but what about a word like bbabba, it will return true too, as the first letter is not a vowel and last letter is a vowel
you can do id with a regex, one built to match a word with the vowel only at the end, or you could use indexOf - wouldn’t that be easier?

let firstLetters = str.split("").slice(0,str.length-1).join("");

// ^ look here - I think I am checking all letters other than the last letter

That line and the following line do the same thing. They both create a string from the original str string which does not include the last character.

let firstLetters = str.slice(0, str.length - 1);

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?

ah, sorry… didn’t put that much attention

you can use this set of function calls to see if your code behave:

// this should return "bbbbbbbbbay"
let a = "bbbbbbbbb"
console.log(translatePigLatin(a));
// this should return "ibbbbbbbbbway"
a = "ibbbbbbbbb"
console.log(translatePigLatin(a));
// all below should return "ibbbbbbbbbay"
a = "bibbbbbbbb"
console.log(translatePigLatin(a))
a = "bbibbbbbbb"
console.log(translatePigLatin(a));
a = "bbbibbbbbb"
console.log(translatePigLatin(a));
a = "bbbbibbbbb"
console.log(translatePigLatin(a));
a = "bbbbbibbbb"
console.log(translatePigLatin(a));
a = "bbbbbbibbb"
console.log(translatePigLatin(a));
a = "bbbbbbbibb"
console.log(translatePigLatin(a));
a = "bbbbbbbbib"
console.log(translatePigLatin(a));
a = "bbbbbbbbbi"
console.log(translatePigLatin(a));