More people, i understand it but just wondering why this code wont work


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

console.log(mary.phoneNumber); (instead of console.log(contact[1].phoneNumber))


#2

@anazerlui,
Change your

console.log(mary.phoneNumber); (instead of console.log(contact[1].phoneNumber))

into

console.log(mary.phoneNumber +" instead of "+ contact[1].phoneNumber);

#3

I did had the same problem. This is pretty disturbing. We have to create an array. The last part of the task says:
Write a console.log statement that prints out Mary's phone number.
So I have the following 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 ];
console.log(contacts[0].phoneNumber);

This last line: 'console.log(contacts[0].phoneNumber);` displays Mary's phone number, but I keep getting an error message.
I find the right line here in Forum, which would be 'console.log(mary.phoneNumber);' so it displays the same result. Why does anyone has an explanation why this ansewer is the preffered one:
'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 ];
console.log(mary.phoneNumber);'


#4

Hi this part

var contacts = [bob,mary ];
console.log(contacts[0].phoneNumber);

You know that the array start conting from 0 so if you use console.log(contacts[0].phoneNumber) it will print bob phoneNumber instead of mary, if you want to print Mary phoneNumber try it like that

var contacts = [bob,mary ];
console.log(contacts[1].phoneNumber);

#5

Oh, this is an obvious mistake. I did not saw that the numbers are different. Thanks for your help :slightly_smiling: