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 trialRaymond Espinoza
1,989 PointsFizzbuzz
Code won't work what am I missing?
func fizzBuzz(n: Int) -> String {
// Enter your code between the two comment markers
Formatted Johns code to make it easier to read.
func fizzbuzz(n: Int) -> String {
switch (n % 3 == 0, n % 5 == 0) {
case (true, false): return "Fizz"
case (false, true): return "Buzz"
case (true, true): return "FizzBuzz"
default: return String(n)
}
}
Add an Answer
// End code
return "\(n)"
}
1 Answer
Jhoan Arango
14,575 PointsHello: Raymond.
Your approach is a very interesting one, in fact is a really good one. I did some fixing on it, but the concept of your code still the same.
func fizzbuzz(n: Int) -> String {
switch (n % 3 == 0, n % 5 == 0) {
case (true, true): // This condition should go first
return "FizzBuzz"
case (true, false):
return "Fizz"
case (false, true):
return "Buzz"
default: break // Here we can break the execution
}
return "\(n)"
}
Unfortunately, this does not pass in the compiler, but IT does work perfectly. So you can say that you did find a solution t the challenge, which ultimately is the purpose of this.
Now, if you want to give it a try again, you can try using an if statement.. You'll challenge yourself again doing it like that, and you'll see that you will be able to pass.
Good job on your solution.