7. Search for a friend - Help!


#1


7. Search for a friend


Help can't figure out what's wrong?

ReferenceError: steve is not defined


var friends = {
    bill:{
        firstName: "Bill",
        lastName:"Bob",
        number: "415-254-3898",
        address: ['One Microsoft Way', 'Redmond', 'WA', '98052']
        },
    steve:{
        firstName:"Steve",
        lastName:"Jobs",
        number: "415-254-3998",
        address: ['1450 3rd Street', 'San Francisco', 'CA', '94158']
        }
};

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

var search = function(name){
    for(var firstName in friends){
        if(name === firstName){
            console.log(friends[name]);
            return friends[name];
        }
        else{
            console.log("There is no such friend in your phone book");
        }
    }
};

search(steve)


#2

steve might not be defined, but you've got an object whose attributes are friends, one of them is a steve


#3

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