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

fancygiraffe
fancygiraffe
2,785 Points

What's wrong with this code?

I've followed the solution step-by-step and my solution still isn't running. Please halp!

https://w.trhou.se/8jsmw2xs2l

3 Answers

On line 20 you have:

if (search = null 

It should be:

if (search === null 
fancygiraffe
fancygiraffe
2,785 Points

Great catch!

Can you help me understand the logic behind why the first line (search = null) is causing the rest of the program not to function?

If you add the following to your code and watch the console:

 for (var i = 0; i < students.length; i += 1) {
    student = students[i];

    console.log(student.name)
    console.log(search)  

    if ( student.name === search ) {

You will see search now has a value of false when using the assignment operator in the if statement. Since there is no match nothing is printed to the screen.