我正在进行codecademy.com javascript课程,我的联系信息完成时遇到问题。它正在返回,但我收到一个错误,通知我它没有返回史蒂夫。我一直在绞尽脑汁这么多我无法直接看到......
链接如下 http://www.codecademy.com/courses/javascript-beginner-en-3bmfN/0/7
var friends = new Object();
friends.bill = new Object();
friends.steve = new Object();
friends.steve.firstName = "steve";
friends.steve.lastName = "jobs";
friends.steve.number = "317-222-3344";
friends.steve.address = ["one apple way","california","us"];
friends.bill.firstName = "bill";
friends.bill.lastName = "gates";
friends.bill.number = "327-332-3322";
friends.bill.address = ["one microsoft way","washington","us"];
var list = function (name){
for(var key in name){
console.log(friends[key]);
}
};
var search = function(name){
for(var key in friends){
if(friends[key].firstName === name){
console.log(key);
return search;
}
}
};
search("bill");
search("steve");
list(friends);
答案 0 :(得分:1)
您正在返回搜索功能。 只需将其更改为您想要的内容即可。
return friends[key];
var friends = new Object();
friends.bill = new Object();
friends.steve = new Object();
friends.steve.firstName = "Steve";
friends.steve.lastName = "jobs";
friends.steve.number = "317-222-3344";
friends.steve.address = ["one apple way","california","us"];
friends.bill.firstName = "Bill";
friends.bill.lastName = "gates";
friends.bill.number = "327-332-3322";
friends.bill.address = ["one microsoft way","washington","us"];
var list = function (name){
for(var key in name){
console.log(friends[key]);
}
};
var search = function(name){
for(var key in friends){
if(friends[key].firstName === name){
var f = friends[key];
console.log(f.firstName,f.lastName,f.number,f.address);
return f;
}
}
};
search("bill");
search("Steve");
答案 1 :(得分:1)
测试正在寻找区分大小写的名称,它首先查找“Steve”。将每个名字改为标题案例,你将通过。