JavaScript program to count the number of vowels in a string:

python tutorials and learn python

Created with Sketch.

JavaScript program to count the number of vowels in a string:

function countVowels(str) {
  let vowels = "aeiouAEIOU";
  let count = 0;
  for (let i = 0; i < str.length; i++) {
    if (vowels.indexOf(str[i]) != -1) {
      count++;
    }
  }
  return count;
}

console.log(countVowels("javascript"));

Leave a Reply

Your email address will not be published. Required fields are marked *