javascript vowels code example
Example 1: how to make a vowel counter in javascript
const vowelCount = str => {
let vowels = /[aeiou]/gi;
let result = str.match(vowels);
let count = result.length;
console.log(count);
};
Example 2: how to make a vowel counter in javascript
function getCount(str) {
let vowelList = 'AEIOUaeiou'
let vowelsCount = 0;
for(var i = 0; i < str.length ; i++)
{
if (vowelList.indexOf(str[i]) !== -1)
{
vowelsCount += 1;
}
}
return vowelsCount;
}
Example 3: how to make a vowel counter in javascript
function countVowels(str) {
return str.match(/[aeiou]/g).length;
}
Example 4: find vowels in string javascript
var name = userInput[0];
var count =0;
function findvowel(name)
{
var vowel = ['a','e','i','o','u','A','E','I','O','U'];
for(i=0;i<name.length;i++)
{
if(vowel.includes(name[i]))
{
count++;
}
}
return count;
}
console.log(findvowel(name));