3.Displaying people


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

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

console.log(printPerson[0]);
console.log(printPerson[1]);

what's wrong with this code?


#2

"wrong"?
Please rephrase in terms of what you want it to do and what it does instead.


#3

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?

this is what i get


#4

Okay. It says you didn't print something. Did you?


#5

Don't know if I lost you or you're buried in your code, so I'll just leave this:

My point is that errors contain information about what happened that you can verify and follow up on.

It's not just "wrong" and it's also not just not printing. Keep digging. Until you can't any more, and then ask for help about the specific part where you are really stuck, if that happens at all.

If it says something wasn't printed, then you'll need to consider why it would have been printed and then compare that to what's happening in your code.

So, you'd start somewhere in the middle of that action and find out if everything is as it should be at that point of time, and then you'll be able to tell which half of the action you'll need to look at next. Repeat until mistake is found.

To find out what's being done, print out what it is doing.


#6

It' s wrong
console.log(printPerson[0]);
console.log(printPerson[1]);

It's correct
console.log(printPerson(contacts[0]));
console.log(printPerson(contacts[1]));


#7

You do not need the console.log part when calling it. since the function contains the console.log, simply just use

printPerson(contacts[0]);
printPerson(contacts[1]);