Search for a friend - help please


#1



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


I keep getting the error: "ReferenceError: Bill is not defined". Pls help. Thank you.


var friends = {
    bill: {
        firstName: "Bill",
        lastName: "Gates",
        number: "(206) 555-5555",
        address: ['One Microsoft Way','Redmond','WA','98052']
    },
    steve: {
        firstName: "Steve",
        lastName: "Jobs",
        number: "(123) 456-7890",
        address: ['One Apple Way','Cupertino','CA','12345']
    }
};

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

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

search(Bill);


#2

this line

search(Bill);

you should put " " around Bill


#3

Thank you!

I am trying to understand the theory behind this... why are they making us include both console.log and return?

console.log(friends[key]);
return(friends[key]);

#4

Even I never understood why they aske us to use both.... if you run it here repl.it you will see that it's print twice one is green which is the one that has been return .


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.