Learn
Exam

Count the Number of Vowels in a String

Difficulty
STARTER

Problem

Given a string word, write a function solution that returns the number of vowels ("a", "e", "i", "o", "u") in the string.


Constraints

  • word consists only of lowercase English letters.
  • The length of word is between 1 and 100 inclusive.

Test Case

Test Case Number word return
1 "hello" 2
2 "algorithm" 3
3 "sky" 0

Explanation for Test Case 1

  • When word = "hello", the vowels are "e" and "o", totaling 2, so the return value is 2.

Explanation for Test Case 2

  • When word = "algorithm", the vowels are "a", "o", and "i", totaling 3, so the return value is 3.

Explanation for Test Case 3

  • When word = "sky", there are no vowels, so the return value is 0.