[英]Javascript codecademy 5.5 function doesn't return correct data
Thanks for having a look at my question! 感谢您看我的问题! I'm trying to complete the JavaScript course in codecademy and this has me stumped.
我正在尝试完成codecademy中的JavaScript课程,这让我很困惑。 I can't even find help in the codecademy forums.
我什至在代码学院论坛上找不到帮助。 I am trying to figure out why "Bob Jones" isn't logged to the console.
我试图弄清楚为什么“ Bob Jones”没有登录到控制台。 Any help is greatly appreciated.
任何帮助是极大的赞赏。 Here is my code:
这是我的代码:
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");
The problem is that JavaScript is case sensitive and the array length is available under the length
property, not Length
. 问题是JavaScript区分大小写,并且数组长度在
length
属性(而不是Length
下可用。
PS learn to use a debugger. PS学会使用调试器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.