Can anyone find whats wrong with my code please?


#1

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

var contactsLength = [0, 1];

function list() {
var contactsLength = contacts.Length;
for(var i = 0; i < contactsLength; i++) {
printPerson (contacts[i]);
}
};

list(contacts);


#2

var contactsLength = [0, 1];

That is creating a new array of 2 number 0 and 1.
The intention on saving the length of the array to a variable is so you can use it in the for loop.

As written your for loop is equivalent to:
for (var i = 0; i < [0, 1]; i++)

What you want is the actual length of the array contacts. Try setting var contactsLength = contacts.length