Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS

Jordan Gorrell
Jordan Gorrell
6,627 Points

FizzBuzz Function Error

Hi everyone, I wanted to take the FizzBuzz exercise in Swift a step further and make it into a function where you can select the range of numbers that the are getting "FizzBuzzed." I'm having a problem with it. I'm getting an error that says:

"ERROR at line 25, col 11: missing argument label 'high:' in call fizzBuzzer(100,150) ^ high: "

Here is my code. I'd really like to know what is going wrong with it so any help is appreciated. I'm assuming it's a simple fix and I've just missed something. Thanks

let fizz = "Fizz"
let buzz = "Buzz"

func fizzBuzzer(low: Int, high: Int) {
    let counter = low...high

    for count in counter {
        switch count {
            case count where count % 3 == 0 && count % 5 == 0:
                print("\(count) makes \(fizz+buzz)")
            case count where count % 3 == 0:
                print("\(count) makes \(fizz)")
            case count where count % 5 == 0:
                print("\(count) makes \(buzz)")
            default:
                print("\(count)")
        }
    }
}

fizzBuzzer(100,150)

1 Answer

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,692 Points

Hey Jordan,

You are missing the second external variable name in your function call. If you put

fizzBuzzer(100, high: 150)

your code will execute with no errors. I could go into a very long explanation, but I would mostly be quoting the Apple Dev Docs. So, if you want, you can read up on functions and function calls at your leisure.

But, other than that... nice code. :)

:dizzy: