Skip to main content
🧩 Algorithms & Problem Solving

Count the Vowels

Counting characters that match a set is a common subtask. A regex with the global + case-insensitive flags finds them all:

"Hello".match(/[aeiou]/gi); // ["e","o"]

.match returns null when there are no matches, so guard with || [].

Your task

Write countVowels(str) that returns the number of vowels (a, e, i, o, u), case-insensitive.

⚑ 30 XP
solution.jsRuns in your browser
Loading editor…
Tests3 to pass
"hello" β†’ 2
"xyz" β†’ 0
"AEIOU" β†’ 5

Run your code to check these.