Need help,thank you so much


#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 (){

for(var i=0;i<=contacts.length;i++){
printPerson(contact[i])
};
};

list()

Oops, try again. Your code threw a ReferenceError when trying to call list(). Make sure you properly defined the function list! Here's the message: ReferenceError: contact is not defined


#2

The culprit in your list() function...


#3

Hey @yuin_hsin ! Your have one problem:

First you mispelled contacts in your for loop whitich i will show you now.

Your spotted Code problem:

Your suppose to say
printPerson(contacts[i]);

Like this:

for(var i=0;i<=contacts.length;i++){
printPerson(contacts[i])
};

Hope that solved the problem! If it didnt Reply to me saying so and ill do my best to help. Good Luck!


#4

Firstly,thanks for your patient explain.But,there is also a problem.
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(){

for(var i=0;i<=contacts.length;i++){
printPerson(contacts[i])
};
};

list()


#5

Sorry but im out of ideas, didnt it print wasnt it suppose to do that? Ahh sorry man im awfully sorry i cant help you. :anguished:


#6

The iterator is going out of range. Set the inequality to < so this does not happen.

    i < contacts.length;

#7

Thanks for your helping anyway :smile:


#8

Yeah No Prob :frowning:


#9

You solve the problem,great