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 trialHaitham Alam
2,685 PointsIt does't work
why it doesn't work?
func fizzBuzz(n: Int) -> String {
// Enter your code between the two comment markers
for n in 1...100 {
if (n % 3 == 0) && (n % 5 == 0) {
return("FizzBuzz")
} else if (n % 3 == 0) {
return("Fizz")
} else if (n % 5 == 0) {
return("Buzz")
} else {
return(n)
}
}
// End code
return "\(n)"
}
4 Answers
Ryan Huber
13,021 PointsYou have the correct logic for figuring out the fizz buzz challenge. Great job. According to the instructions you don't need to worry about the loop. Just the logic. Strip out everything except the logic from your answer:
func fizzBuzz(n: Int) -> String {
// Enter your code between the two comment markers
if (n % 3 == 0) && (n % 5 == 0) {
return("FizzBuzz")
} else if (n % 3 == 0) {
return("Fizz")
} else if (n % 5 == 0) {
return("Buzz")
}
// End code
return "\(n)"
}
Haitham Alam
2,685 PointsThanks, i have just put the answer between the comments as the instruction says.
Ryan Huber
13,021 PointsSorry. I haven't done that particular challenge yet. According to the instructions you don't need to worry about the loop. Just the logic. Strip out everything except the logic from your answer:
func fizzBuzz(n: Int) -> String {
// Enter your code between the two comment markers
if (n % 3 == 0) && (n % 5 == 0) {
return("FizzBuzz")
} else if (n % 3 == 0) {
return("Fizz")
} else if (n % 5 == 0) {
return("Buzz")
}
// End code
return "\(n)"
}
Hope that helps.
Haitham Alam
2,685 Pointsby the way, your is not working as well :D
Ryan Huber
13,021 PointsYeah. I didn't do that challenge before answering. Try my updated answer. Let me know if that helps out. Thanks.
Haitham Alam
2,685 PointsDone. last one is ok
Ryan Huber
13,021 PointsGlad it worked. If you don't mind, could mark the answer as correct so others can benefit from it. Thanks and good luck!