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 trialAnton Berezin
4,451 Pointsis it ok? can't go to the next step because an error occurred if (n%3 == 0) {return "Fizz" }
if (n%3 == 0) {return "Fizz" }
else if (n%5 == 0)
{return "Buzz"
}
else if (n%3 == 0) && (n%5 == 0)
{return "FizzBuzz"
}
func fizzBuzz(n: Int) -> String {
// Enter your code between the two comment markers
if (n%3 == 0)
{return "Fizz"
}
else if (n%5 == 0)
{return "Buzz"
}
else if (n%3 == 0) && (n%5 == 0)
{return "FizzBuzz"
}
// End code
return "\(n)"
}
3 Answers
Nate Meyer
3,887 PointsHey Anton,
IOS Code Challenges are down at the moment while a partner performs maintenance. Should be back shortly. You can keep an eye on our maintenance page: status.teamtreehouse.com. Sorry for the inconvenience!
Nate Meyer
3,887 PointsIOS challenges are back up!
Anton Berezin
4,451 PointsThanks!
Jennifer Nordell
Treehouse TeacherAnd now that the challenges are back up, let's take a look at your code. You have a logic flaw. If I send in the value 60, it should return "FizzBuzz". But your code says to look and see if it's divisible by 3, which 60 is. So right now, if I send in 60 (which is both evenly divisible by 3 and 5) your code is going to return "Fizz". Remember that once a return statement is hit the function exits. And once an if statement evaluates to true, it never continues downwards to the other else if
statements. Try reordering what you're testing for and make the most restrictive condition first. Hope this helps!
Anton Berezin
4,451 PointsThank you so much!