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 trialRicardo Wilson
Courses Plus Student 2,428 PointsIf Statement Challenge
I can't figure out what is missing from my code for the Challenge. For some reason it is responding by "Cannot invoke == with an argument list of type ([Int], IntegerLiteral...
Can I get some help please and thank you.
let months = [1, 2, 3]
for month in months {
if months == 1 {println("January")
}
else if months == 2 {println("Febraury")
}
else if months == 3 {println("March")
}
}
3 Answers
Greg Kaleka
39,021 PointsHey Ricardo,
You're very close, but take another look at what you're checking. The error message says you can't use == to compare [Int]
to an integer (it says integer in a complicated way, but that's what it means). Note the square brackets in [Int]
. That means you're trying to check to see if an array is equal to an integer.
As you iterate through the months
array, you need to check if your working variable, month
is equal to the integer in question.
let months = [1, 2, 3]
for month in months {
if month == 1 {
println("January")
}
// etc...
Note I also changed the formatting a bit - this is how you'll typically see people write blocks of code like this - it's more readable too.
Good luck!
-Greg
nobodyinhere
3,418 Pointslet 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")
}
}
kjvswift93
13,515 PointsYou need to use "month" instead of "months" in your if statements. Also you misspelled February.
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")
}
}