Search doesn't work properly


#1



https://www.codecademy.com/en/courses/javascript-beginner-en-3bmfN/0/7?curriculum_id=506324b3a7dffd00020bf661


My problem is that is doesnt only print the contact info for Denis, but for everyone, I dont see what I did wrong.. Can anyone else see what I did wrong? Thank you.


var friends = {
    bill: {
        firstName: 'Bill',
        lastName: 'Gates',
        number: '(111) 111-1111',
        address: ['Gates Drive','Las Vegas','CA','111111']
        },
    steve: {
        firstName: 'Steve',
        lastName: 'Jobs',
        number: '(222) 222-2222',
        address: ['Jobs Drive','Miami','FL','222222']
        },
    denis: {
        firstName: 'Denis',
        lastName: 'Tur',
        number: '(333) 333-3333',
        address: ['Tur Drive','Plymouth','MN','333333']
        }
};

var list = function(par) {
    for (var key in par) {
        console.log(key);
    }
}

list(friends);

var search = function(name) {
    for (var key in friends) {
        if (friends[key].firstName === name) {
            console.log(friends[key]);
            return friends[key];
        }
    }
}

search('Denis');


#2

For less verbose output, comment the call to list(). Remember that the SCT calls the function, too, so the output may be duplicated.


#3

I'm not sure what SCT means, also if i comment the list(friends); then it doesnt print out the list... lol not sure what that has to do with this. Also if I comment the search('Denis'); it still prints out 3 contacts, two of which are Steve and one is Bill, why isn't Denis printed out? Really don't know what I did wrong..


#4

Submission Correctness Test -- the lesson checker program behind the exercise.

There is nothing wrong with your code, that I can see. Is it letting you pass the exercise?


#5

Oh, ok thanks. So basically the SCT can make duplicates, but if I were to use some other editor it wouldnt make the duplicates.. (I tried and i think it worked)

Thanks :slight_smile:

And yea it does let me pass, I just didn't want to pass with mistakes which I could repeat later.