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 trial

iOS Swift Collections and Control Flow Control Flow With Conditional Statements FizzBuzz Challenge

FizzBuzz

this works in xcode but tth gives me a "bummer"

func fizzBuzz(n: Int) -> String { // Enter your code between the two comment markers if (n%3==0) && (n%5 == 0) {return "fizzfuzz"} if n % 3 == 0 {return "Fizz"} if n % 5 == 0 {return "Fuzz"} return "(n)" }

fizzBuzz.swift
func fizzBuzz(n: Int) -> String {
    // Enter your code between the two comment markers
    if (n%3==0) && (n%5 == 0) {return "fizzfuzz"}
    if n % 3 == 0 {return "Fizz"}
    if n % 5 == 0 {return "Fuzz"}
    return "\(n)"
}

3 Answers

The strings you are returning are incorrect.

If the number is a multiple of five, you should return "Buzz", not "Fuzz".

Also, if the number is a multiple of both 3 and 5, it should return "FizzBuzz". You need correct capitalization (in Swift, "a" and "A" are totally different letters, so you need to match up the uppercase/lowercase letters exactly or the challenge won't expect it!) and the message is supposed to be "fizz" and "buzz" together, not "fizz" and "fuzz" together.

fizzBuzz.swift
func fizzBuzz(n: Int) -> String {
    // Enter your code between the two comment markers
    if (n%3==0) && (n%5 == 0) {
        return "FizzBuzz"
    }
    if n % 3 == 0 {
        return "Fizz"
    }
    if n % 5 == 0 {
        return "Buzz"
    }
    return "\(n)"
}

I hope this helps. ~Alex

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hey Louis,

You code is 100% correct, except you are not returning the exact strings that the challenge is asking for. Check the spelling and punctuation of the first and last one. You do have "Buzz" correct. Challenges are very picky and specific when it checks the code, so everything needs to be exactly as it instructs in order to pass.

Aside from that... Good Job! :)

Keep Coding! :dizzy:

Haha. Answered at the same time again XD

Thank you!