7/8 What's wrong with my code? help me!thank you


#1

var friends = {};
/*friends.teemo ={
name:"teemo",
favourte:"computer",
address:["shanxi"]
};
friends.jerry = new Object();
friends.jerry.name = "jerry";
friends.jerry.age = 20;
friends.jerry.address = ['china'];
friends.juny = {};
friends.juny["name"] = "juny";
friends.juny["age"] = 20;
friends.juny["address"]= ['china'];*/
friends.bill = new Object();
friends.bill.firstName = "bill";
friends.bill.lastName = "hi";
friends.bill.number = 20;
friends.bill.address = ['xi"an'];
friends.steve = {};
friends.steve["firstName"] = "steve";
friends.steve.lastName = "hello";
friends.steve["number"] = 20;
friends.steve.address = ['china'];
var list = function(obj){
for (var key in obj)
{
console.log(key);
}
}
var search = function(name) {
for(var prop in friends) {
if(friends[prop].firstName === name) {
console.log(friends[prop]);
return friends[prop];
}
}
};
list(friends);
search("steve");


#2

This is what worked for me:

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];
}
}
}


#3

What happens when you run that code? Do you get an error? Or different output than you expect?


#4

yes,it's right,thank you very much.


#5

jmsofts1,this friend has helpd me perfectly, also thank you .


#6

You are welcome cssplayer75301!