Javascript Problem – Find Vowels in String

The purpose of this exercise is to count the number of vowels in a string.  This is actually pretty easy using a regex expression.  I use the match() method to pick out the vowels [aeiou].  The “g” in “/gi” tells the expression to match all occurrences, not just the first one.  The “i” tells it to find either capital or lower case letters.

I used a nested for loop to do it a longer way.

Finally, I used a for…of loop to complete it.  Not as easy as a regex expression, but more efficient than a nested loop.


Leave a Reply

Your email address will not be published.