My function seems to be having trouble updating the totalVowels
variable. Currently, I'm splitting the argument into an array, iterating through it, and incrementing totalVowels
when there's a match with my vowel
regex pattern.
I've tried tweaking different parts of the code to fix this issue, but so far, no luck. It feels like the solution is within reach, but I can't seem to figure it out at the moment.
function VowelCount(str) {
let strArr = str.split('');
let totalVowels = 0;
let vowel = /a|e|i|o|u/gi
for (let i = 0; i < strArr.length; i++) {
if (strArr[i] === vowel) { totalVowels++ }
}
return totalVowels;
}
console.log(VowelCount('vowel'));