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

Bryce Patrick
Bryce Patrick
10,099 Points

Not 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!

fizzBuzz.swift
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)"
}
Tabatha Trahan
Tabatha Trahan
21,422 Points

Do 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?

1 Answer

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hey 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! :)