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

Can't seem to figure it out?

Can someone explain it more to me?

Thanks,

months.swift
let months = [1, 2, 3]
for month in months {
if month == 1 {
println["January"]
} else if month == 2{
println["February"]
} else if month == 3{
println["March"]
} else {
println[month]
}
}

2 Answers

You are very close. Your first issue is that you have incorrectly written your println functions by using brackets instead of parenthesis. i.e. println["January"] instead of println("January"). Then, you can delete that final else clause because it is unnecessary. The code should end after println("March") }.

Thank you, you were very helpful.

no problem. So the final solution should be this. See if yours matches.

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