Listing Everybody HEEELP Please :)


#1


Hello I'm trying with this exercise but I don't understand it really well. Can you help me please

https://www.codecademy.com/en/courses/building-an-address-book/0/4?curriculum_id=506324b3a7dffd00020bf661#

undefined
undefined
undefined
undefined

Oops, try again. It looks like your list function didn't console.log "Bob Jones". Did you remember to call list(); after creating it?

Replace this line with your 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);
}

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


#2

here..
console.log(printPerson[i]);

hint**
Back to instruction.

Inside of the loop, add code to call printPerson, passing in the element of the array that the loop is currently at.


#3

ok, so...
I guess it goes something like:

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


#4

Can you tell me the array you're looping on ?


#5

yes of course (BTW thanks for the quick response and all the help)

contacts, right?


#6

It is!
now back to instruction..

Inside of the loop, add code to call printPerson, passing in the element of the array that the loop is currently at.


#7

ok I understand that part

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

but still have this error
Oops, try again. It looks like your list function didn't console.log "Bob Jones". Did you remember to call list(); after creating it?


#8

Inside of the loop, add code to call printPerson, passing in the element of the array that the loop is currently at.

Not the Array but Elements?

hint**
if x is an array,

x = [1,2,3,4]
then x[0] , x[1] etc are its elements/items.


#9

ok, the elements are bob and mary, right? and the parameters of the contacts are firstName, etc...

so what I understand is that by doing printPerson[bob, mary]; is going thru the parameters of the elements bob and mary.


#10

Thank you very much got it... now took me forever to understand :confounded:

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


#11

try using printPerson(contacts[i]); --then you're making actual use of your i variable in the for loop, i believe


#12

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