Last Updated: June 7, 2026
The task is a membership test. Five letters are vowels: a, e, i, o, and u. The other twenty-one are consonants. Is the given letter one of those five? If yes, it is a vowel; if no, a consonant.
The complication is case. A and a are both vowels, but a computer treats them as different characters with different codes. Rather than list all ten vowel forms, normalize the input first. Convert the character to lowercase, and you compare against five letters.
E and e are treated the same.The most literal way to express "is this one of these five letters" is a chain of equality checks joined by OR. Lowercase the character, then ask whether it equals a, e, i, o, or u. If any is true, the letter is a vowel. If all five fail, it falls through to consonant.
ch to lowercase so case no longer matters."Vowel"."Consonant".Input:
The input is the uppercase letter E. Lowercasing it gives e. Now compare against the vowels: it does not equal a, but it does equal e, so the OR chain short-circuits to true on the second comparison. The letter is a vowel.
Dispatching a single variable against a fixed list of constants reads more directly as a switch than as a chain of OR comparisons. List the five vowel cases together, let them share one outcome, and treat everything else as the default.
The behavior is identical to the comparison chain. The difference is readability: the five vowels line up as labeled cases, and the default branch makes the "everything else is a consonant" rule explicit. You still normalize to lowercase first so you need five case labels instead of ten.
ch to lowercase.a, e, i, o, and u, return "Vowel"."Consonant".Input:
The input is b, which is already lowercase. The switch looks for a matching case among the five vowels. None of them is b, so control falls to the default branch, which returns "Consonant".