3. Displaying People


#1

I'm getting error message with my code saying: 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? here's my ouput:

{ 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 here's my 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];

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

Thanks for the help in advance.


#2

Move these lines outside of the printPerson() function. They should call the function with the array element as arguments.

printPerson(contacts[0])

and so on.


#3

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

thanks i figured it out.

here's whats wrong from the previous code:

function printPerson (person) { function error in this line.
console.log(person.firstName = " " + person.lastName); and the = in this line
console.log(contacts[0]);
console.log(contacts[1]); and like your suggestion moving this outside the printPerson function

Thanks again.


#4

Hey @jdm316 glad you got it sorted. In future it would be great if you can use the format code button, will make it a lot easier for others to read!


#5

@alexcraig ok will do.


#6

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