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
- count = 0
- Characters left?
- ch = next character, lower case
- ch in "aeiou"?
- count = count + 1
- Return count