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

Julius Manubay
Julius Manubay
2,603 Points

Problem may be with quiz compiler

I'm not quite sure why the compiler isn't accepting my code. When I type it out I can see that everything after the interpolated n in the default statement is green, meaning that it's a string. When I preview this posting everything looks normal, I wish I could attach a screenshot to this, but in my view I see..

} // End Code return "(\n)" }

in a green text, which to me means it is a string, everything except the parenthesis after return are colored green. Which I think is the reason why it is not compiling. Everywhere else I check to see if my code is correct says it is correct and it works in my xcode playground. Hopefully i'm not asking a really dumb question.

Thanks in advance,

fizzBuzz.swift
func fizzBuzz(n: Int) -> String {
  // Enter your code between the two comment markers
  switch n {
  case n % 3 == 0 && n % 5 == 0: return "FizzBuzz"
  case let n where n % 3 == 0: return "Fizz"
  case let n where n % 5 == 0: return "Buzz"
  default: return "\(n)"
  }
  // End code
  return "(\n)"
}

1 Answer

Sarah Hurtgen
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Sarah Hurtgen
Treehouse Project Reviewer

Hi! Not a dumb question!

I copied and pasted your code into the code challenge to see what you meant, and it changes the color of the end section for me as well, but I don't necessarily think it means it's reading it as a string. You have a default value at the end of your switch statement, so you're code will never get to the lines after "// End code". I think the color change is just trying to bring attention to that, so you're aware the end section is never executed (this is just my best guess though, I'm not completely sure if that's what is happening). The directions specify that you should not provide a default statement since they did it for you, if you backspace out your "default" line, it fixes the coloring issue in the compiler.

However, when I put your code into my playground, it does bring up a couple different errors. The code challenge compiler brings up this error as well, it reads:

... error: expression pattern of type 'Bool' cannot match values of type 'Int'
    case n % 3 == 0 && n % 5 == 0: return "FizzBuzz"

I would recommend approaching the challenge using 'if' statements rather than 'switch' statements, and it may help resolve some of these issues.

Hope that helps!