Search for friends


#1


var friends = new Object()
friends.bill = new  Object()
friends.steve = new Object()
var friends = {
bill: {
    firstName: "Bill",
    lastName: "Griffin",
    number: "1234567",
    address: ['Raspberry road ' , 'Sint Peters']
    }
};
    
    var friends = {
        steve:{
            firstName: "Steve",
            lastName: "Jobs",
            number: "24681012",
            address: ['Wesly street' , 'Colebay']
            }
        };
        
    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

What is wrong with my code? it doesnt return the information for steve


#3

the property is firstName, look what you use in your search function


#4

oh i see i my typed firstName


#5

now it isn't returning the information for bill


#6

you make a friends object with one property: bill

then you make a new friends object with one property: steve

So what do you have then in the end? one friends object with one property (steve)


#7

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