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

JavaScript JavaScript Loops, Arrays and Objects Tracking Data Using Objects The Student Record Search Challenge Solution

Ahmed Abdellatef
Ahmed Abdellatef
11,095 Points

The extra challenge code

When I write multiple wrong names in the prompt dialogue, it just display only the first wrong name that I entered and this only in case I write wrong names before right names in the prompt dialogue. But if I write the right names first then the wrong ones the wrong ones don't show up. here's my code. check please the last if statement I wrote and tell me what's wrong. I'm still trying for 3 days till now and get depressed. https://w.trhou.se/tnhcyycjuv

3 Answers

Steven Parker
Steven Parker
229,695 Points

Every call to "print" replaces the content of the "output" div. If you want to see the results of multiple calls you would need to add to the display instead of replacing it:

    outputDiv.innerHTML += message;  // note += instead of =
Ahmed Abdellatef
Ahmed Abdellatef
11,095 Points

Thanks for replying. I did like you said but the problems still the same the only change is that when I write a name isn't in the list it displays twice. And the other problems still alive: 1. when I write multiple names ( right and wrong ) in the prompt dialogue it just shows up the right names if the first name I entered exists in the list. 2. If I start the names in the prompt dialogue with a name not in the list it just shows that name and if I wrote another wrong names they don't show up. Is there any solution ? if you answered the extra challenge code can you share it with us?

Steven Parker
Steven Parker
229,695 Points

On second look, I see my previous suggestion isn't needed (or desirable) because "message" keeps growing.

But I also notice that "notHere" is not being reset for each search:

  notHere = 0;  // do this before search loop starts
  for (var i = 0; i < students.length; i += 1) {
Steven Parker
Steven Parker
229,695 Points

I'm glad I could help.   Happy coding!

Ahmed Abdellatef
Ahmed Abdellatef
11,095 Points

Yeahhhh! It's working now as I intended. Thank you very much.