I'm trying to make a JavaScript function that tells how many times a vowel was repeated in a given string.
Here's what I have tried:
function checkVowel(str) {
vowels = ['a', 'e', 'i', 'o', 'u']
str = "hello world"
for(let i = 0; i < str.length; i++){
if(str[i].includes(vowels)){
console.log("worked")
} else {
console.log("not worked")
}
}
}
checkVowel()
How can I make this function check for each vowel rather than the entire array at once?
str[i].includes(vowels)=>vowels.includes(str[i]). You might also want to remove the hardcodedstr = "hello world"--call the function withcheckVowel("hello world")instead, so you can reuse the function for different strings.