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 trialBryce Patrick
10,099 PointsNot returning proper fizz value
Bummer! I'm receiving a code challenge error stating that i need to double check which values i'm returning for Fizz and attaching them to the right string? Can some familiar with this challenge determine what i am doing wrong?
Thank you!
func fizzBuzz(n: Int) -> String {
// Enter your code between the two comment markers
if (n % 3 == 0) && (n % 5 == 0) {
print("FizzBuzz")
} else if (n % 3 == 0) {
print("Fizz")
} else if (n % 5 == 0) {
print("Buzz")
} else {
print(n)
}
// End code
return "\(n)"
}
1 Answer
Jason Anders
Treehouse Moderator 145,860 PointsHey Bryce,
Your code is correct, except for 2 things that the challenge is asking for.
First, the challenge want you to return
the statements, and you are using print
Second, the code specifically says to not worry about the 'default' case, but you still added an else
Change the print
to return
and delete the else
statement and you'll be good to go.
Keep Coding! :)
Tabatha Trahan
21,422 PointsTabatha Trahan
21,422 PointsDo you have a range of numbers to loop this through, like for n in 1..100 or what ever the range is you're working with?