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

Omotayo Olawepo
Omotayo Olawepo
2,803 Points

hi i don't know what i got wrong over here. could yall help me out :)

if i'm far off just give me a hint but if i like just spelt something wrong or it's something very minimal it would be great if you point it out. thanks :)

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

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

1 Answer

Brendan Whiting
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Brendan Whiting
Front End Web Development Techdegree Graduate 84,735 Points

You're just missing an "if" in the last one to print out "March". Yes, sometimes you can just use an "else" statement, but you don't put a condition with the else statement, the else case would be for any other cases. And in this example, that isn't what you want. You would only want to print out "March" with the number 3, not with any other number that might be there.