Search for a friend- pls help not getting it


#1

var friends = new Object();
friends.bill = new Object();
friends.steve = new Object();
var friends = {
bill:{
firstName: "Bill",
lastName: "Brono",
number: "(081) 3040-7330",
address: ['one ebony oroazi road', 'Rumuola','Rumunkara','3956']
}
};
var friends = {
steve:{
firstName:"Steve",
lastName: "Strope",
number: "(070) 5295-5329",
address:['two kaduna kaduna road', 'Rumuadaolu','Rumuakpara','4956']
}
};
var list = function (friends){
for (var number in friends){
console.log (number);
}
};
var search = function (name){
for (var details in friends){
if (friends[details].firstName === name){
console.log(friends[details]);
return friends[details];
}
}
};
list(friends);
search('bill');


#2

These lines are not needed. The objects are defined in the literals that follow them.

You are declaring friends too many times. Both bill and steve literals should be written into in one friends object.

var friends = {
    bill: {

    },
    steve: {

    }
};

#3

didn't see that coming..great
thanks@mtf
got it.


#4

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