3. Displaying People - Need Help


#1

I need help with this exercise, I tried different ways and none worked.

This is the error message:

Oops, try again. It looks like your function didn't log "Bob Jones" to the console. Did you remember to call your function on bob?


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

// printPerson added here
var printPerson = function(person){
    console.log(contacts.firstName + " " + contacts.lastName);
    };
    
    printPerson.contacts[0];
    printPerson.contacts[1];


#2

here..

printPerson.contacts[0];
printPerson.contacts[1];

printPerson() is a function so you need to pass contacts[0] and contacts[1] as argument of it.

Dot notation is used when we want to access value using key from an Object .


#3

I've change it and still not working I am getting the same error

var printPerson = function(person){
    console.log(contacts.firstName + " " + contacts.lastName);
    };
    
    printPerson(contacts[0]);
    printPerson(contacts[1]);

#4

problem in this line of code..
console.log(contacts.firstName + " " + contacts.lastName);

You're trying to access firstName and lastName from contacts,
contacts is an Array.
One more thing your printPerson() function's parameter is person but you're not using it?
person here is an object that represents mary or bob!


#5

OMG... thanks a lot now that worked just fine ! Cheers ! ;d


#6

Cheers!!! :thumbsup:


#7

console.log(person.firstName + " " + person.lastName);
//contracts is an Array


#8

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