Why can't I find Steve?


#1

I'm able to pull data on bill... but not steve...

var friends = {}
var friends = {
bill : {
firstName : "Bill",
lastName : "Willaims",
number : "555-555-5555",
address : ["55 way st", "crazy place"]
},
steve : {
firstName : "Steve",
lastName :"jobs",
number :"123-345-3332",
address : ["loopy drive", "fantasy land"]
}
};

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

else {
return null;
}

}
};

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

}

else {
console.log("nope")
return null;
}

}
};

list(friends);
search("steve");

#2

After lots and lot's of trouble, I finally got a code that working for 7\8, hope it helps:

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


#4

With some help from a friend... i got it to FINALLY do what I originally intended -

var friends = {
       bill : {
        firstName : "Bill",
        lastName : "Willaims",
        number : "555-555-5555",
        address : ["55 way st", "crazy place"]
        },
      steve : {
        firstName : "Steve",
        lastName :"Stevens",
        number :"123-345-3332",
        address : ["loopy drive", "fantasy land"]
        }
 };


var list = function() {
    for (var prop in friends) {
        console.log(friends[prop]);
    }
};

var search = function(name) {
    var found = false;
    for (var prop in friends) {
        if(prop.toUpperCase() == name.toUpperCase){ 
            found = true;
            console.log(friends[prop]);
            break;
        }
    }
    if(!found) {
        console.log("nope");
    }
};

//list(friends);
search("bill");