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 trialChris Lopez
8,155 PointsBummer! Double check your logic for Fizz values and make sure you're returning the correct string!
Why?! It works in the playground
import Foundation
func fizzBuzz(n: Int) -> String {
// Enter your code between the two comment markers
let n = Int(arc4random_uniform(20))
if n % 3 == 0 { return "Fizz" }
else if n % 5 == 0 { return "Buzz" }
else { return "FizzBuzz" }
// End code
return "\(n)"
}
3 Answers
Kieran Black
9,139 PointsHi Chris,
Try removing the following line:
let n = Int(arc4random_uniform(20))
as n is supplied by the challenge.
Also, your fizzbuzz check needs amending as currently this would fire for values that are not a multiple of 3 or 5
Gimore Murdock
Courses Plus Student 3,374 PointsThe first condition in your if statement must be the fizzbuzz condition which is ((n % 3) == 0 & (n % 5) == 0) so that if the number is both divisible by 3 and 5 the fizzbuzz condition will catch it, and then the rest of the condition follows
Chris Lopez
8,155 PointsSpoke too soon still not working