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 trialivan salas
iOS Development with Swift Techdegree Student 3,417 Pointscode works perfect in xcode, but wont pass when i copy and paste on to web page?? says i need to check logic values...
tells me to check logic for fizzbuzz values and make sure it is returning correct string??
func fizzBuzz(n: Int) -> String {
if n % 3 == 0 {
return "Fizz"
}
else if n % 5 == 0 {
return "Buzz"
}
else if n % 3 != 0 && n % 5 != 0 {
return "FizzBuzz"
}
return "\(n)"
}
1 Answer
Jason Anders
Treehouse Moderator 145,860 PointsHey Ivan,
Actually the code won't work "perfectly" in Xcode. If you pass in a value of 60, you will only "Fizz" when you should get "FizzBuzz".
The problem lies with your logic setup. 60 will return true
after the first if
statement, and then the execution will stop. Even though 60 is also divisible by 5, it will never reach that condition.
With this in mind, the condition check for "FizzBuzz" needs to be the first condition you check. Make sense?
Keep Coding! :)
ivan salas
iOS Development with Swift Techdegree Student 3,417 Pointsivan salas
iOS Development with Swift Techdegree Student 3,417 PointsTHANKS! very helpful. worked after corrections you mentioned.