Facebook Pixel

Count Vowels

JavaScript
easy
10 mins

Write a function countVowels that takes a string as input and returns the number of vowels in that string. Vowels include both lowercase and uppercase characters: 'a', 'e', 'i', 'o', 'u' and 'A', 'E', 'I', 'O', 'U'.

Example Inputs & Outputs

countVowels("hello") // → 2 (e, o) countVowels("JavaScript") // → 3 (a, a, i) countVowels("bcd") // → 0 countVowels("AEIOU") // → 5 countVowels("") // → 0

Constraints & Edge Cases

  • Input will always be a string.
  • String may contain spaces, punctuation, or numbers — these are not vowels.
  • Function should be case-insensitive (handle both uppercase and lowercase).
  • An empty string should return 0.

Solve Similar questions 🔥

Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.