Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

Count Vowels

Data Structures, Operators & Stringseasy

Course · Section 9: Data Structures, Modern Operators and Strings · Lecture 128: Working With Strings - Part 1

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

Sample tests

Input: countVowels("hello")
Output: 2
Input: countVowels("rhythm")
Output: 0

+ 2 hidden tests run on Submit.

Hints

Common pitfalls
  • match returns null when nothing matches, which breaks .length.

Learning resources

  • MDN: String.prototype.match
Approach & explanation (try first)

A global case-insensitive vowel match, guarded against null, gives the vowel count.

Loading...
⌘/Ctrl + Enter

Run your code to see results.