Skip to content
Exercise · Conditions and loops · lesson 12 of 13

Exercise: count the vowels

Write a function function countVowels(text) that returns how many vowels the string text contains. The vowels are a, e, i, o and u.

  • countVowels("javascript") → 3
  • countVowels("hello world") → 3
  • countVowels("rhythm") → 0

Constraints: text consists of lowercase Latin letters and spaces and may be an empty string, for which the answer is 0; the letter y does not count as a vowel.

Do not add extra imports unless the task says so explicitly.

vowels.js — javascript
javascript · 4 lines
Ctrl+Enter run · Esc leave editor

Subscribe to take the course

The course is free. Sign in with Telegram and subscribe to the channel to open every lesson.

Sign in another way