JSFiddle - React, Tailwind, and code Playground
by colorkid
JavaScript
const findVowels = str => {
let count = 0
const vowels = ['a', 'e', 'i', 'o', 'u']
str = str.toLowerCase();
const arr = str.split('');
arr.forEach((item) => {
if(vowels.includes(item)) {
count++
}
});
/*for(let char of str.toLowerCase()) {
if(vowels.includes(char)) {
count++
}
}*/
return count
}
console.log(findVowels('hello')); // --> 2
console.log(findVowels('why')); // --> 0