TryBugHunt
goLogic errorEasy

Vowel count misses vowels in capitalised words

BugFind the bug and fix the code

What it should do

countVowels(text) counts the vowels a, e, i, o and u in text, in either case. countVowels("Apple") returns 2.

What happens instead

countVowels("Apple") returns 1, and countVowels("OUT") returns 0.

package main

import "strings"

func countVowels(text string) int {
    count := 0
    for _, r := range text {
        if strings.ContainsRune("aeiou", r) {
            count++
        }
    }
    return count
}

Test a custom input to verify an edge case (e.g. empty lists, negative numbers, duplicates).

⏱️0:00
Hints
🏆 0 hints = Flawless Solve
Think & Test Cooldown
2:00 remaining

Take a moment to read the bug symptom and trace the code with Run & Check before unlocking Hint 1.

Hint 2
Unlocks after Hint 1
Hint 3
Unlocks after Hint 2

This bug belongs to the logic errors pattern

The wrong operator, an inverted condition, a formula the right way round but backwards.

What you'll practise

An easy Go debugging exercise about logic errors: the wrong operator, an inverted condition, a formula the right way round but backwards.

The checks your fix must pass

Signs of this kind of bug

Spoiler: why this bug happens(try it first; the hints get warmer one at a time)

Character comparison in Go is exact: 'A' and 'a' are different runes with different numbers. The set "aeiou" only matches lowercase letters, so capital vowels are skipped. Either include both cases in the set or lowercase the rune first with unicode.ToLower. Any check on letters typed by people should decide on case explicitly, and its tests should include capital letters.

The pattern behind it: logic errors.

More logic errors to practise

Embed this challenge on your site

Paste this into any web page or blog post. Visitors fix the bug right there, in their browser.

<iframe src="https://trybughunt.com/embed/c27b37fe-6523-4674-95e3-de3e4c1dd357" title="Debugging challenge: Vowel count misses vowels in capitalised words" width="100%" height="580" loading="lazy" style="border:1px solid #d4d4d8;border-radius:12px;max-width:760px"></iframe>
<p style="font-size:14px">Debugging challenge from <a href="https://trybughunt.com/challenges/c27b37fe-6523-4674-95e3-de3e4c1dd357">TryBugHunt</a></p>