Contact List lesson 7.Searce for a friend


#1

Plz, help me. I Can`t understand why the code is not working properly
var friends = new Object();

friends.Bill = new Object();
friends.Bill.firstName = "Bill";
friends.Bill.lastName = "Gates";
friends.Bill.number = "(555) 555-5555";
friends.Bill.address = ['One Microsoft Way','Redmond','WA','98052'];

friends.Steve = new Object();
friends.Steve.firstName = "Steve";
friends.Steve.lastName = "Jobs";
friends.Steve.number = "(555) 555-5556";
friends.Steve.address = ['washingtonstreet','Washington','WA','92352'];

friends.Denis = new Object();
friends.Denis.firstname = "Denis";
friends.Denis.lastName = "Kalushka";
friends.Denis.number = "334343-343-343";
friends.Denis.address = ['Gagarina avenue','Kiev','WA','23423'];

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

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

            }
        }
    }

list();
search('Denis');

But the result is (there is no Denis at all...) :

{ firstName: 'Steve',
lastName: 'Jobs',
number: '(555) 555-5556',
address: [ 'washingtonstreet', 'Washington', 'WA', '92352' ] }
{ firstName: 'Steve',
lastName: 'Jobs',
number: '(555) 555-5556',
address: [ 'washingtonstreet', 'Washington', 'WA', '92352' ] }
{ firstName: 'Bill',
lastName: 'Gates',
number: '(555) 555-5555',
address: [ 'One Microsoft Way', 'Redmond', 'WA', '98052' ] }


#2

This is the reason it is not found. firstName.

You'll get less verbose output if you comment the list() line.

Also note that the key names should be lowercase, bill, steve, denis, but that's not a dealbreaker like the above noted typo.