Hello

The task Return the number of data vowels in the string

Here is my code

function getCount(str) { var vowelsCount = 0; var vowels = ['a', 'e', 'i', 'o', 'u']; var modernStr = str.split(''); for (var i = 0; i < modernStr.length; ++i) { if(modernStr.includes(vowels[i])) vowelsCount++ } return vowelsCount; } getCount('aviiiiiii') 

But it does not work, I can not understand why
I will be grateful for the help

  • what is expressed does not work ? - Alexey Shimanskyj
  • @ AlekseyShimansky incorrectly counts the number of vowels in a line - Zhukov Roman

2 answers 2

You made a mistake in if , correctly like this:

 if(vowels.includes(modernStr[i])) vowelsCount++ 
  • Hmm, really, it works that way. But why didn't it work for me? Can it be on my fingers? - Nikita Shchypylov
 for (var i = 0; i < modernStr.length; ++i) { if(vowels.includes(modernStr[i])) vowelsCount++ } 

for will be executed modernStr.length times, which means that you will need to select modernStr [i] and not vowels [i].

  • Thank you very much! Something nedoper himself - Nikita Shchypylov