I have tried passing strings to the getCount
function that contain ‘aeiou’ and not but the value of vowelsCount
is always 0
.
I tried using string includes()
function using the documentation, but it always returns count as 0, I have the code with which we can get the exact number of vowels in a string, but I prefer to use the approach taught by MDN docs.
This is the approach i prefered:
const vowelCount = str => {
let voweslCount = 0;
for ( let char of str){
if (str.includes('aeiou'))
voweslCount++;
}
return voweslCount;
}
2
Answers
Try splitting up the problem into smaller easier to reason about functions:
You can also start by creating an array containing each letter of the string, then transform each letter of that array into an array with map()
function. Then check with includes() if each array containing letters includes vowels