JavaScript Program to Count the Number of Vowels in a String

bookmark

// program to count the number of vowels in a string

function countVowel(str) { 

    // find the count of vowels
    const count = str.match(/[aeiou]/gi).length;

    // return number of vowels
    return count;
}

// take input
const string = prompt('Enter a string: ');

const result = countVowel(string);

console.log(result);

 

 

Output

Enter a string: JavaScript program
5