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!

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

Aramik YOUSEFZADEH
PLUS
Aramik YOUSEFZADEH
Courses Plus Student 895 Points

Compiling problem

this is what I get :

Your code could not be compiled. Please click on "Preview" to view the compiler errors.

fizzBuzz.swift
func fizzBuzz(n: Int) -> String {
  // Enter your code between the two comment markers
  for n 1...100 {

  if (n%3==0) && (n%5==0) {
  return("FizzBuzz")
    } else if (n%3 == 0) {
    return("Fizz")
    } else if (n%5 == 0) {
    return ("Buzz")
    } else return(n) 


  // End code
  return "\(n)"
}

1 Answer

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,826 Points

Hey there,

Your code is correct in syntax, but you missed the final two points in the instructions. Remember, instructions need to be followed exactly or the challenge will return a Bummer!.

The last two parts of the instructions state:

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.

The challenge also does not need you to loop over a range of values (using for or while). I'll take care of that.

You have added a loop, so that needs to be deleted.

You also added a default case, so you'll also need to delete your else statement.

Other than that, it's all good.

func fizzBuzz(n: Int) -> String {
  // Enter your code between the two comment markers

  if (n%3==0) && (n%5==0) {
    return("FizzBuzz")
    } else if (n%3 == 0) {
      return("Fizz")
    } else if (n%5 == 0) {
      return ("Buzz")
    }

  // End code
  return "\(n)"
}

Keep Coding! :dizzy: