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

KRIS NIKOLAISEN
PRO
KRIS NIKOLAISEN
Pro Student 45,225 Points

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?

KRIS NIKOLAISEN
PRO
KRIS NIKOLAISEN
Pro Student 45,225 Points

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.