/..

Dark Mode

Enable Console

The Function

countVowels([''])
countVowels(str)

/*
  Counts how many vowels exist in a word
*/

countVowels('Codewars'); 
// 3

countVowels('Need4Swede');
// 4

Solution by - Need4Swede

How it works

countVowels(str) {
  
  // Initialize counter
  let vowelsCount = 0;
  
  // Initialize filter
  const vowels = ['a', 'e', 'i', 'o', 'u', 'y'];
  
  // Split our input into a lowercase array of chars
  str = str.toString().toLowerCase().split("");
  
  // If a char exists in our filter, add 1 to counter
  for (let i = 0; i < str.length; i++){
    if (vowels.includes(str[i])){
      vowelsCount += 1;
    }
  }
  
  // Return counter total
  return vowelsCount;
}

Try it yourself - Codewars Source

You can also use my built-in JavaScript console