4.listing everybody. Works but doesnt pass the exercise


#1



Oops, try again. It looks like your list function didn't console.log "Bob Jones". Did you remember to call list(); after creating it?
it does log the info. I am sorry i couldnt load a screenshot. what am I doing wrong? Does it want me to do something in a specific way and I am misssing it? I keep seeing variations of this line of code in other people's exercises "console.log (printPerson(contacts[i]));". Someone please explain what's happening to me.Thank you!


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

};
 };
list();

it prints out: 


lastName: 'Jones',
  phoneNumber: '(650) 777-7777',
  email: 'bob.jones@example.com' }
{ firstName: 'Mary',
  lastName: 'Johnson',
  phoneNumber: '(650) 888-8888',
  email: 'mary.johnson@example.com' }
{ firstName: 'Bob',
  lastName: 'Jones',
  phoneNumber: '(650) 777-7777',
  email: 'bob.jones@example.com' }
{ firstName: 'Mary',
  lastName: 'Johnson',
  phoneNumber: '(650) 888-8888',
  email: 'mary.johnson@example.com' }
 

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


#2

i think you deleted this line of code

function printPerson(person) {
    console.log(person.firstName + " " + person.lastName);
}

click on reset button then you can see. read the instruction again and do the follwing.......


#3

Oh god I did..
I amended the code and now it works and makes sense when it askes "add code to call printPerson, ".
Thank you so much rcodeman!!


#4

I think there is one more error. In your code in function LIST is:
...
...
var printPerson =contacts[i];
console.log(printPerson);

// first line deleting and rewriting created function printPerson - its wrong
// ..so delete both of those lines and type there:

    printPerson(contacts[i]);

if you need to see all that script .... here is:

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 (i=0; i<contactsLength; i++) {
printPerson(contacts[i]);
};
};

list();
//------------------------------------------------------------------------


#5

Yep, that's how I did it when I undeleted - function printPerson(person) {
console.log(person.firstName + " " + person.lastName);
}-
and it worked. Thank you anyway!


#6

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