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
Dale O Shea
535 PointsError in compile
Hey,
So I getting the following error when trying to compile. "Binary Operator '==' cannot be applied to operands of type String and [String]"
From what I can tel it is the exact same as what Amit has in his video.
Would appreciate help.
func searchNames(#name: String) -> Bool { let names = ["Dale","Martin","Sonya","Junior","Shauna"]
var found = false
for n in names {
if n == names {
found = true
}
}
return found
}
searchNames(name: "Dale")
1 Answer
Martin Wildfeuer
Courses Plus Student 11,071 Points if n == names
Within your loop you are comparing the String n with the Array names. Comparing a string with an array won't work, but as you are looking for a specific name, your code should read
if n == name
This way, you are comparing two strings, the parameter name you passed to the function and a single name contained in the namesarray.