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

FizzBuzz

i tried every thing to solve this challenge but i coud not i don't know way

fizzBuzz.swift
for n in 1...100 {
    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 )
    }
}

1 Answer

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hey there,

While your code is correct in syntax, it is not following the very specific instructions the challenge asks for:

  1. Step #2 "... You also don't need to define n. It is defined in the function provided ... The challenge also does not need you to loop over a range of values (using for or while). I'll take care of that." -- you created a loop, so that needs to be removed.

  2. Step #3 "Change all your print statements to return statements. For example: print("FizzBuzz") becomes return "FizzBuzz". -- you still have "print", so those need to be changed.

  3. "Note: Do not worry about the default case" -- you have an "else" statement, so that will also need to be deleted.

Overall, just refactor your code to match exactly what the challenge needs to verify the answer and you're good to go.

Keep Coding! :dizzy: