7. contact list


#1

Keep getting undefined error - I'm sure once that is solved another will crop up - care to take a look?

var friends =  {};
friends.bill = {
firstName: "Bill",
lastName: "Gates",
number: 5551231234,
address: ['One Microsoft Way', 'Redmond', 'WA', '98052']
};

friends.steve = { 
 firstName: "Steve",
 lastName: "Jobs",
 number: 3025551212,
 address: ['1 Infinite Loop Way', 'Cupertino', 'CA', '99988']
};

var list = function(friends) {
for(var firstName in friends) {
 console.log(firstName);   
}
}
var search = function(friends) {
    for(var firstName in friends){
     if(friends.bill === 'Bill') {
     console.log(friends.bill[i]);
    }   
     else{
        console.log('Try again')
    }
};
    var search = function(friends) {
    for(var firstName in friends) {
     if(friends.bill === 'Steve') {
     console.log(friends.steve[i]);
    }   
     else{
        console.log('Try again')
    }

7. Contact List
#2

Check your brackets at the last two blocks of code, you're missing a few.
It's healthier to make a habit of it :slight_smile:

Check it

var search = function(friends) {
  for(var firstName in friends) {
    if(friends.bill === 'Bill') {
      console.log(friends.bill[i]);
    } else {
      console.log('Try again')
    }
  }
};


var search = function(friends) {
  for(var firstName in friends) {
    if(friends.bill === 'Steve') {
      console.log(friends.steve[i]);
    } else {
        console.log('Try again')
    }
  }
};

#3

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