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 trialvamosrope14
14,932 PointsWhy is my code not working? I've tried everything.
.
2 Answers
Steven Parker
231,236 PointsThe determination that the student is not in the list should only be made after the loop has finished checking all the students. Then, and only if nothing was found, should the failure message be output.
A boolean might be handy to keep track of whether anything was found inside the loop.
To elaborate a bit: everything in the "else" part of the conditional should be moved after the loop. Doing it inside causes every test that doesn't match to be handled as a "not found". But you can expect that most of the names won't match. What's important is finding out if any of them match, which you won't know until the loop has finished.
vamosrope14
14,932 Points.
Steven Parker
231,236 PointsThat's why I was suggesting a boolean might be useful to keep track if a name had been found. Also, I expanded my answer a bit.