Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

Could someone help me with this???

My playground gets the right answer all day, but the system keeps spitting it back.. I have no idea what's up. Cause I'm getting the answer it wants....

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

fizzBuzz(n: 18)

1 Answer

Dave Harker
PRO
Dave Harker
Pro Student 15,510 Points

Hi Isaac Gonzalez,

You've done a great job there. Just need to read the challenge a little more closely.
(code is fine, just does not meet challenge requirements)

func fizzBuzz(n: Int) -> String {
    // Enter your code between the two comment markers
    if n % 5 == 0 && n % 3 == 0 {
        return "Fizz Buzz" //return "FizzBuzz" not "Fizz Buzz"
    } else if n % 5 == 0 {
        return "Buzz"
    } else if n % 3 == 0 {
        return "Fizz"
    } else { 
        // you can leave this final else in if you like, but the challenge specifically says it isn't required
        // Note: Do not worry about the default case (where the number doesn't match Fizz, Buzz, or FizzBuzz).
        // The code in the challenge editor already takes care of that by returning the number as a string using string interpolation.
       return String(n)
    }
    // End code
}

fizzBuzz(n: 18)  // also not required

You're doing great! Keep going :dizzy:
Dave

Dave Harker
Dave Harker
Pro Student 15,510 Points

Isaac Gonzalez — You can mark the question solved by choosing a "Best Answer".
And happy coding! :sparkles: