Implement the method countVowels that returns the number of vowels present in a given string.

Learner Level
String Manipulation Loop
Write a function that takes a string as input and counts how many vowels it contains. The vowels to be counted are: a, e, i, o, u — both uppercase and lowercase should be considered.
Example 1
Input:
s (string) = hello
Return:
(int) 2
Example 2
Input:
s (string) = AEIOU
Return:
(int) 5
Example 3
Input:
s (string) = Programming
Return:
(int) 3
Example 4
Input:
s (string) = This is a test
Return:
(int) 4

To count the number of vowels in a string, follow these steps:

  1. Initialize a Counter
    Start with a variable set to 0 to track the vowel count.

  2. Iterate Through the String
    Loop over each character in the input string.

  3. Check for Vowels
    For each character, check whether it is a vowel (a, e, i, o, u), considering both lowercase and uppercase.

  4. Update the Count
    If it is a vowel, increment the counter.

  5. Return the Final Count
    After the loop finishes, return the count as the result.

Pseudocode:

Function countVowels(s):
    Initialize count ← 0
    For each character ch in s:
        Convert ch to lowercase
        If ch is 'a' or 'e' or 'i' or 'o' or 'u':
            Increment count by 1
    Return count
Run your code to see the result.