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 FizzBuzz Challenge

Daniele Santos
Daniele Santos
16,536 Points

My code is working on playground, but it's not working on your platform

This is the code:

if (n % 3 == 0) , (n % 5 == 0) {
    print("FizzBuzz")
}else if (n % 3 == 0){
    print("Fizz")
} else if (n % 5 == 0) {
    print("Buzz")
}
fizzBuzz.swift
func fizzBuzz(n: Int) -> String {
     if (n % 3 == 0),(n % 5 == 0) {
        print("FizzBuzz")
    }else if (n % 3 == 0){
        print("Fizz")
    } else if (n % 5 == 0) {
        print("Buzz")
    }
  return "\(n)"
}
Daniele Santos
Daniele Santos
16,536 Points

I've already solved the problem. It had to do with the prints I requested, instead of returns!

1 Answer

Greg Kaleka
Greg Kaleka
39,021 Points

Hi Daniele,

Glad you solved this on your own. For future reference, if code is compiling in playgrounds, that just means you haven't made any syntactical mistakes (I see a lot of students posting about their code "working on their machine", and it's often just that their program doesn't crash :blush:). That doesn't always mean you're doing what the challenge is asking, though!

There are some common gotchas, and this is definitely one of them - return vs print. Keep an eye out for that!

Happy coding!

Cheers :beers:

-Greg