7. Search for a friend totally lost


#1



enter link description here


I have tried all the solutions posted nothing seems to help can some one tell me what I am doing wrong?:frowning:
Oops, try again. It looks like your search function doesn't return contact information for Steve.


    var friends = {};
        bill = {
        firstName: "Bill",
        lastName: "Murray",
        number:"(555) 555-5555",
        address: ['234 1st Street', 'Edmonton', 'AB', 'T6J 3R7']
        },
        
        steve = { 
        firstName: "Steve",
        lastName: "Jacobs",
        number: "(666) 666-6666",
        address: ['8907 MacEwan way', 'Edmonton', 'AB', 'T5B 4P1']
        }
var list = function (friends){
    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];
    }
    }
};
list(friends);
search("Steve")


#2

Hi the error come from your object friends

    var friends = {};
        bill = {
        firstName: "Bill",
        lastName: "Murray",
        number:"(555) 555-5555",
        address: ['234 1st Street', 'Edmonton', 'AB', 'T6J 3R7']
        },
        
        steve = { 
        firstName: "Steve",
        lastName: "Jacobs",
        number: "(666) 666-6666",
        address: ['8907 MacEwan way', 'Edmonton', 'AB', 'T5B 4P1']
        }

did you see it now?


#3
var friends = {};
    bill = {
    firstName: "Bill",
    lastName: "Murray",
    number:"(555) 555-5555",
    address: ["234 1st Street", "Edmonton", "AB", "T6J 3R7"]
    },
    
    steve = { 
    firstName: "Steve",
    lastName: "Jacobs",
    number: "(666) 666-6666",
    address: ["8907 MacEwan way", "Edmonton", "AB", "T5B 4P1"]
    }

fixed comma issue but still receiving same error.


#4

and here you could do it like that

var friends = {
    bill : {
    firstName: "Bill",
    lastName: "Murray",
    number:"(555) 555-5555",
    address: ["234 1st Street", "Edmonton", "AB", "T6J 3R7"]
    },
    
    steve : { 
    firstName: "Steve",
    lastName: "Jacobs",
    number: "(666) 666-6666",
    address: ["8907 MacEwan way", "Edmonton", "AB", "T5B 4P1"]
    }
}

or like that

var friends = {};
    friends.bill = {
    firstName: "Bill",
    lastName: "Murray",
    number:"(555) 555-5555",
    address: ["234 1st Street", "Edmonton", "AB", "T6J 3R7"]
    },
    
    friends.steve = { 
    firstName: "Steve",
    lastName: "Jacobs",
    number: "(666) 666-6666",
    address: ["8907 MacEwan way", "Edmonton", "AB", "T5B 4P1"]
    }