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 Collections and Control Flow Control Flow With Conditional Statements Solution to FizzBuzz

rory Stevens
rory Stevens
3,840 Points

Why would you not use switch instead of if as it is more "powerful" and better able to deal with complex situations?

Can it be done using switch instead? Why is that not the best option? Fully appreciate any help, cheers.

Jeff McDivitt
Jeff McDivitt
23,970 Points

You could but an if statement is much easier

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

1 Answer

Logan Cornelius
Logan Cornelius
16,876 Points

I also don't understand why not use a switch instead. Is a switch statement not more scaleable? Don't really understand why we would ever use multiple else if statements in place of a switch statement when it seems to be essentially the same thing.