JavaScript: Count the number of vowels in a given string
JavaScript Basic: Exercise-54 with Solution
Count Vowels in String
Write a JavaScript program to count the number of vowels in a given string.
This JavaScript program counts the number of vowels (a, e, i, o, u) in a given string. It iterates through the string, checks each character to see if it is a vowel, and keeps a running total of the vowels encountered.
Visual Presentation:

Sample Solution:
JavaScript Code:
Output:
1 5
Live Demo:
Flowchart:

ES6 Version:
For more Practice: Solve these Related Problems:
- Write a JavaScript program that counts the total number of vowels in a string, treating both uppercase and lowercase vowels equally.
- Write a JavaScript function that returns an object mapping each vowel to its frequency within the given string.
- Write a JavaScript program that counts vowels in a string using regular expressions without iterating through each character.
Go to:
PREV : Check 'a' and 'b' Separated by Exactly 3 Places.
NEXT : Check Equal Number of 'p's and 't's.
Improve this sample solution and post your code through Disqus.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.