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 trialAntony Gabagul
9,351 PointsCode won't work
Unfortunately my code won't compile, and I can't seem to find a reason. Thanks
func fizzBuzz(n: Int) -> String {
// Enter your code between the two comment markers
switch n {
case (n % 6 == 0) : print("Fizz")
case (n % 5 == 0) : print("buzz")
case (n % 6 == 0 && n % 5 == 0) : print("FizzBuzz")
default: print(n)
}
// End code
return "\(n)"
}
3 Answers
Paul Brazell
14,371 PointsIf/Else statement would be better here. Change your cases to If statements.
Jennifer Nordell
Treehouse TeacherKeep in mind that also all print statements need to be changed to return as indicated by the instructions. Also, you're supposed to have it as determining if divisible by 3 and 5. Not 6 and 5.
That being said, the very next video shows you the solution. Happy coding!
James Tench
43,891 PointsThe reason is because you are switching on the value of n. Therefore you cannot make it part of a conditional statement like you have it in the case statement.
I would try the challenge with an if else if else type of check.
If you want to use a switch I think you need to use the "where" keyword in your case statements.