Hi I am trying to count the vowels of the input of the form in my HTML using javascript currently with no success.
Here is my HTML
Looking at the other answers, I think this is The Simplest Solution
One line of code and case insensitive. It splits the string at vowels and returns the array length. Why make it more complicated with loops and switch statements?
update: I really like freefaller's solution using match(), which is equal in simplicity. The solution here has a slight edge in that it has wider browser support. Would be interesting to know if there's any speed advantage between the methods.
Solution:
var vowels = text.split(/[aeiou]/gi).length - 1;
Run code snippet to test:
Vowel Counter Demo
Count:0