Finding that special someone


#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 list = function() {var contactsLength = contacts.length;
for (var i=0; i<contacts.length; i++) {printPerson(contacts[i]);}
}

list(contacts[i]);

Oops, try again. You have the following error in your code: ReferenceError: i is not defined

Why?


4. Finding that special someone
#2

Hi. Well you have issue with calling for list() function. You are trying to pass it a parameter contacts[i] when that function is not accepting any parameters.

You should be calling it with

// code 
list();
// you have it like list(contacts[i]); instead

Fix that for start, and what you have will list all people inside contacts list.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.