More people

https://www.codecademy.com/courses/building-an-address-book/0/2?curriculum_id=506324b3a7dffd00020bf661#

I dont see whats wrong?

error: make sure mary is second in concatcs



var bob = {
    firstName: "Bob",
    lastName: "Jones",
    phoneNumber: "(650) 777-7777",
    email: "bob.jones@example.com"
};

var mary={
    firtName: "Mary",
    lastName: "Johnson",
    phoneNumber: "(650) 888-8888",
    email:"mary.johnson@example.com"
};

var contacts = ["bob","mary"];

console.log(mary.phoneNumber)


1 Like

I haven’t done this specific lesson, but it seems that the contacts array should have the names of the variables, not the strings:
var contacts = [bob,mary];

1 Like

tried that too, still same error

figured it out now, it was the space between my one " and the ( for mary’s phone number

Try doing this

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 = new Array();
contacts[0] = bob;
contacts[1] = mary;
console.log(contacts[1].phoneNumber);
6 Likes

I’ve noticed on Stackoverflow they state you should just create the array implicitly var contacts = ;. They list a bunch of reasons, but just seeing it’s probably more common means it’s the best use.

PS. I like Mikes contacts[1].phonenumber. I’m surprised it works like that. I tried all kinds of ways to get it out of contacts like: console.log(contacts[mary.phonenumber]); …contacts[1.phonenumber] …contacts[1.3] so surprised how Mike’s version works. It really illustrates that just the contents of bob and mary are moved into the contacts array. Try console.log(contacts); and you’ll see that the origianl array names bob and mary are gone.

@reallynolieyahoo.com
As comment to your

that should be

Try console.log(contacts); and you’ll see that
the Array-Elements contain
the associated object Values of the variables bob and mary .

What if I wanted to print Mary’s phone number, but I didn’t know her position in the array? Could I do that just knowing that the name of the object is ‘mary’?

1 Like

you would probably use a “for” loop to count through the objects in the array and then use a conditional “if” firstName is “mary”… etc etc

@gendakel

but you should use the toLowerCase() Method of the string-Prototype
on the associated string Value of the firstName property
as it might be a capitalized string.

1 Like

I tried that exact same code as mikesargsyan did above, and it didn’t work for me. I kept getting “SyntaxError: Invalid or unexpected token.”

@andyville130
Well, then please give us the FULL code you are using now…
and also a link to the exercise you are writing about…

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

1 Like

@coremaster49089

console.log( contacts[1].phoneNumber );
4 Likes

your code should be like:

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

2 Likes

Thanks for your help. It was a simple error that I over looked.

Thank you mikesargsyan

1 Like

@joshua.t.monk
Hi,

I have tried this and this worked for me. Check out:

var bob = {
firstName: “Bob”,
lastName: “Jones”,
phoneNumber: “(650) 777-7777”,
email: "bob.jones@example.com"
};

var mary = new Object();

mary.firstName = “Mary”;
mary.lastName = “Johnson”;
mary.phoneNumber = “(650) 888 - 8888”;
mary.email = "mary.johnson@example.com";

var contacts = [bob,mary];

console.log(contacts[1].phoneNumber);

1 Like

var bob = {
firstName: “Bob”,
lastName: “Jones”,
phoneNumber: “(650) 777-7777”,
email: "bob.jones@example.com"
};

var mary = new Object();
mary.firstName = “Mary”;
mary.lastName = “Johnson”;
mary.phoneNumber = “(650) 888-888”;
mary.email = "mary.johnson@example.com";

var contacts = [bob, mary];

console.log (contacts[1].phoneNumber);

TypeError: console.log is not a function

why??? :frowning:

I dont know why it does not work