7. why isnt mine working


error= Oops, try again. It looks like your search function doesn't return contact information for Steve.

var friends ={
        firstName: "Bill",
        lastName: "Asce",
        number: "404 918 5654",
        address:['2547 bradford square ne','atlanta','ga','30345']

       firstName: "Steve",
       lastName: "Bhandari",
       number: "12345 664 4",
       address:['2551 bradford square ne','atlanta','ga','32659']

  var list= function(friends){
      for(var firstName in friends)
  var search=function(friends){
      for(var name in friends){
              return friends[name];


friends is the global object. In this parameter we need a name.

var search = function (name) {

Now cycle through the friends object as you are, except with a generic local variable. key is quite commonly used in this instance since that is what we are iterating... keys.

    for (var key in friends) {


Now there is no collision with the name variable. The if statement should not contain an else statement. Just the if.

        if (friends[key].firstName === name) {


Lastly, we are asked to both log the object, and return it.

            return friends[key];

Piece this all together and study the result. It should begin to make sense. This exercise is more about mechanics than practical application. Study and practice this before moving on to the next unit. If need be, do this whole unit again just to reinforce the hidden lessons.


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