4/6 Blinded by the Code - What's wrong here?


#1

Can someone tell me what I'm missing? ...I keep receiving "SyntaxError: Unexpected token. )"

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

};

list(contacts);


#2

it should have been i<contacts.length; or i<contactsLength;

and list shouldn't take any parameters. change it to list(); only


#3

Great ...got that working! Now, it's printing out the names 2x, then gives the error...

"TypeError: Cannot read property 'firstName' of undefined."

How can it return this error after it found and printed FN and LN?


#4

Found my problem.

Changed:
for(var i = 0; i <= contactsLength; i++)

To:
for(var i = 0; i < contactsLength; i++)
(removed the =)

Thanks for your assistance!