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

I can't tell what's missing from my code here, and the only error message is "Try Again!" What should I do?

It doesn't tell me what's wrong with my code.

months.swift
let months = [1, 2, 3]

for index in months {
  if months == [1] {
    println("January")
  } else if months == [2] {
    println("February")
  } else if months == [3] {
    println("March")
  }
  println(months[index])
}

2 Answers

Jeremy Faith
PLUS
Jeremy Faith
Courses Plus Student 56,696 Points

First, change months to index in your if statements. The variable index will take on each value of the array as the for in statement loops over the array months. Second, remove the brackets around the numbers 1, 2, and 3 in your if statements. You do not need the brackets since index is taking the an int value from the months array and [1] is an array itself and not an int. Finally, remove the last println statement println(months[index]).

Thanks!