iOS Swift Collections and Control Flow Control Flow With Conditional Statements FizzBuzz Challenge

Correct code is not working

I have entered the code correctly but I am getting the error "Bummer! Double check your logic for Fizz values and make sure you're returning the correct string!" Any idea what this is on about?

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) {
    } else if (i % 3 == 0) {
    } else if (i % 5 == 0) {
    } else {
  // End code
  return "\(n)"

2 Answers

Steve Hunter
Steve Hunter
Treehouse Moderator 57,656 Points

Hi Phil,

Firstly, the question states The challenge also does not need you to loop over a range of values (using for or while). I'll take care of that.

The question is particular about Change all your print statements to return statements. For example: print("FizzBuzz") becomes return "FizzBuzz".

Also, Change your variable/constant name that you are checking in each step to n

Lastly, Do not worry about the default case (where the number doesn't match Fizz, Buzz, or FizzBuzz)

Just put your if statements within the code comments; no for loop, no prints; just the if logic. Your code works, but the above needs fixing.

Try changing that and see what issues you see then.

Let me know how you get on.


Hi Steve,

I made the changes and it worked. I think I’m trying to over think some to these answers. Really appreciate your help!