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: