Confused, please help! >contact list> ex 7


#1

var friends = {
bill:{
firstName: "Bill",
lastName: "Bob",
number:"07448549443",
address: ["1st street", "new york way"]
},
steve:{
firstName:"steve",
lastName:"martin",
number:"0475458435",
address: ["12th street", "madison avenue"]
}
};

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

var search = function(friends){
for(var key in friends){
if(name==key){
return name;
}
else{
console.log("The names don't match.");
}
}
}


#2

you indeed some a bit confused. Okay, lets start with the instructions:

Define a function search that takes a single argument, name

lets look at your function:

var search = function(friends)

your argument seem to be friends, it should be name

then your for loop:

var search = function(name){
  for(var key in friends){
  
  }
}

so far so good. but what does key contains? lets find out:

var search = function(name){
  for(var key in friends){
    console.log(key)
  }
}

so key contains the objects nested inside the friends object (bill and steve)

okay, but we want the first name of bill and steve (not the objects), so we need to access them:

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

now you could compare the firstName of bill and steve object with name, hope this helps


#3

Hey i have code that output bill and steve , but still doesnt pass


#4

but that could also be your list function. Please make a new topic here, so someone can help you, this topic is for thecodingmeatball to be helped


#5

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