感谢您查看我的问题!我试图在codecademy中完成JavaScript课程,这让我很难过。我甚至无法在codecademy论坛中找到帮助。我想弄清楚为什么" Bob Jones"没有登录到控制台。任何帮助是极大的赞赏。这是我的代码:
var bob = {
firstName: "Bob",
lastName: "Jones",
phoneNumber: "(650) 777-7777",
email: "bob.jones@example.com"
};
var mary = {
firstName: "Mary",
lastName: "Johnson",
phoneNumber: "(650) 888-8888",
email: "mary.johnson@example.com"
};
var contacts = [bob, mary];
function printPerson(person) {
console.log(person.firstName + " " + person.lastName);
};
function list() {
var contactsLength = contacts.length;
for (var i = 0; i < contactsLength; i++) {
printPerson(contacts[i]);
}
};
/*Create a search function
then call it passing "Jones"*/
function search(lastName){
var contactsLength = contacts.Length;
for(var i = 0; i<contactsLength; i++){
if(lastName === contacts[i].lastName){
printPerson(contacts[i]);
}
}
};
search("Jones");
答案 0 :(得分:2)
问题是JavaScript区分大小写,数组长度在length
属性下可用,而不是Length
。
P.S。学会使用调试器。