Count the vowels

Return how many vowels (a, e, i, o, u, in upper or lower case) are in the string s.

Write count_vowels(s) in Python, countVowels(s) in JavaScript or TypeScript, or int count_vowels(char s[]) in C. Level: Easy.

Examples

Input: s = 'hello'
Output: 2
Input: s = 'AEIOU'
Output: 5
  • 0 ≤ length of s ≤ 1000
  • "y" is not a vowel here

Hint

Lower-case each character before you check it, then test whether it is one of "aeiou".

The approach, step by step

  1. count = 0
  2. Characters left?
  3. ch = next character, lower case
  4. ch in "aeiou"?
  5. count = count + 1
  6. Return count

← All practice problems

Try AI Flowchart free →