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(s)` returning how many vowels (a, e, i, o, u, any case) appear in `s`.

Sample tests

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

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • match returns null (not []) when nothing matches, which breaks .length.

Learning resources

  • MDN: String
Approach & explanation (try first)

Matching /[aeiou]/gi finds every vowel; guarding the null result with || [] keeps .length safe.

Loading...
⌘/Ctrl + Enter

Run your code to see results.