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
Sergio Pichardo
24,963 PointsStudent Record Challenge
Please help me improve my code, and figure out how to display duplicate names, I honestly have no clue where to start.
4 Answers
Daniel Newman
Courses Plus Student 10,715 PointsGood enough. If you want to improve something maybe you would like to not print "students.length" times "was not found" and store for nothing notFound.push(search) array in case user typed quit as first prompt answer?
Also, you can make your loop working even error/null is typed or cancel pressed and will not break cycle on successful name search?
I saw many forum posts with this quizz and yours have a firm one looking. What is your first programming language?
Sergio Pichardo
24,963 PointsHey Daniel, thanks for the help. I just realized I had a bug in my code. I changed the condition in my else if statement to the following: i === (students.length) -1, but I still don't understand completely what is going on here. I would appreciate it if you could explain this to me.
Oh and my first programming language is Python, but I'm just a newbie.
Daniel Newman
Courses Plus Student 10,715 Pointsstudents.indexOf(search) -1)
It's about getting index number 1...n and decrease it, to get index of array students. If it first one student then you index will be 0 and all if statement become false. But in fact, indexOf return values 0...n and you don't need to decrease it. Look at the documentation.
if (students.indexOf(search) > -1 )
Sergio Pichardo
24,963 PointsThanks Daniel! I understand it now.
Sergio Pichardo
24,963 PointsSergio Pichardo
24,963 Points