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

Double check your logic for Fizz values and make sure you're returning the correct string!

Not sure why the error is popping up.

fizzBuzz.swift
func fizzBuzz(n: Int) -> String {
  // Enter your code between the two comment markers
  for i in 1...100 {
    if(i % 3 == 0) && (i % 5 == 0) {
        print ("FizzBuzz")
    } else if (i % 3 == 0) {
        print ("Fizz")
    } else if (i % 5 == 0) {
    print ("Buzz")
    } else {print (i)
    }
}
  // End code
  return "\(n)"
}

1 Answer

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,858 Points

Hi Chris,

Challenges are very specific, especially this one.

You are getting the error because you did not follow the instructions for the task. These instructions are very specific and need to be followed exactly. If not, you will get the Bummer!

So, you need to fix up your code to match what the instructions are asking you for:

  1. The instructions state that you are not to "loop over a range of values (using for or while), but you have a for loop.
  2. The instructions say to "Change your variable/constant name that you are checking in each step to n", but you still have i.
  3. Step three in the instructions specify that you need to "Change all your print statements to return statements", but you still have print statements.
  4. Finally, the instructions says not to "worry about the default case", but you have an else statement, and this will throw an error.

You'll just need to go back and refactor the code you have to the specifications set out in the instructions, and then it will pass.
Keep in mind, that while this one is extremely picky, all challenges need to have the instructions followed precisely. Even a missing period in a string, or a spelling error, etc will cause the code checker to throw you a Bummer.

Keep Coding! :) :dizzy: