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 trialDaniele Santos
16,536 PointsMy 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")
}
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)"
}
1 Answer
Greg Kaleka
39,021 PointsHi 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 ). 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
-Greg
Daniele Santos
16,536 PointsDaniele Santos
16,536 PointsI've already solved the problem. It had to do with the prints I requested, instead of returns!