Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Swift 2.0 Collections and Control Flow Control Flow With Conditional Statements FizzBuzz

Can i do it with switch statement ?

I already completed this challenge but i also tried to do it with switch statement but i am getting tons of errors. is this challenge can be done with switch? If it is please help me with this...

Josh Minor
Josh Minor
2,947 Points

Its possible, are you getting errors in playground or just the treehouse compiler?

2 Answers

Steven Deutsch
Steven Deutsch
21,046 Points

Hey Ali Sutcu,

I answered this question in a previous post. Check it out here:

https://teamtreehouse.com/community/not-sure-which-part-of-my-code-is-incorrect

Good Luck

I get error on both of them. Here is my code :

func fizzBuzz(n: Int) -> String {
    // Enter your code between the two comment markers
    switch n {
    case n % 3 == 0: return "Fizz"
    case n % 5 == 0: return "Buzz"
    case n % 3 == 0 && n % 5 == 0: return "FizzBuzz"
    default: return "\(n)"
    }
    return "\(n)"
}