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 Basics (retired) Control Flow If Statement

Jordan Olson
Jordan Olson
1,414 Points

Challenge has bug?

Hello all! I have been stuck on this challenge for an hour now, and the code Ive written works because when I put it into my own playground, it prints what is asked of it. If someone could review the challenge or throw me a bone on this one it would be much appreciated. Here is the code I have written. let months = [1, 2, 3]

for month in months { if month == 1 { print("January") } else if month == 2 { print("February") } else if month == 3 { print("March") } }

1 Answer

Richard Lu
Richard Lu
20,185 Points

Hey Jordan,

Your solution is definitely correct, but it is for Swift version 2.0+. The solution that they're looking for needs to be in Swift 1.2 and it isn't far off what you have.

let months = [1, 2, 3]

for x in months {
  if x == 1 {
     println("January")   // print use to be println
  } else if x == 2 {
     println("February")
  } else if x == 3 {
    println("March")
  }
}

Hope I've helped. Happy Coding! :)