Menu
Coddy logo textTech

Challenge: Vowel Counter

Part of the Logic & Flow section of Coddy's Dart journey — lesson 64 of 65.

challenge icon

Challenge

Easy

Create a function called countVowels that analyzes text and counts the number of vowels it contains. This challenge combines string manipulation, loops, and conditional logic to solve a practical text processing problem.

Your task is to:

  1. Create a function named countVowels that takes a single String parameter called text
  2. The function should count all vowels in the text: a, e, i, o, and u
  3. The counting must be case-insensitive (both uppercase and lowercase vowels should be counted)
  4. The function should return an int representing the total number of vowels found
  5. Read a string input from the user
  6. Call your countVowels function with the input string
  7. Print the result with the exact format: Vowel count: X (where X is the number of vowels)

Your function should iterate through each character in the string, convert it to lowercase for comparison, and check if it matches any of the five vowels. Use a counter variable to keep track of the total number of vowels found.

For example, if the input is "Hello World", your program should output:

Vowel count: 3

If the input is "Programming", your program should output:

Vowel count: 3

If the input is an empty string "", your program should output:

Vowel count: 0

Your solution should demonstrate proper use of string iteration, conditional statements to check for vowel characters, and the toLowerCase() method to handle case-insensitive comparison.

Try it yourself

import 'dart:io';

// TODO: Create your countVowels function here

void main() {
  // Read input
  String? text = stdin.readLineSync();
  
  // TODO: Call your countVowels function and store the result
  
  // Output the result
  print('Vowel count: $result');
}

All lessons in Logic & Flow