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 Basics (retired) Control Flow Exercise: FizzBuzz Generator

Anders Lund
Anders Lund
3,061 Points

dont know whats wrong

xCode said that this "{" sign in the code below was "Bracked block of statements is an unused closure"

//if number % 3 == 0 number % 5 == 0 { println("BuzzFizz")

(THE WHOLE CODE)

for number in 1...15{ if number % 3 == 0 number % 5 == 0 { println("BuzzFizz") } else if number % 3 == 0 { println("buzz") } else if number % 5 == 0 { println("fizz") } else { println(number) } }

1 Answer

Christopher Augg
Christopher Augg
21,223 Points

Anders,

No problem. Just a few errors.

1) You are attempting to produce BuzzFizz instead of FizzBuzz.

2) You forgot the && within your first if statement

3) Even though the code will work without parenthesis, it is a good practice to use them for logical testing

      for number in 1...15 {
           if (number % 3 == 0) && (number % 5 == 0) {
              println("FizzBuzz")
           } else if number % 3 == 0 {
              println("Fizz")
           } else if number % 5 == 0 {
              println("Buzz")
           } else {
              println(number)
           }
     }

Hope this helps.

Regards,

Chris