More people


#1

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)


#2

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


#3

tried that too, still same error


#4

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


#5

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

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.


#7

@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 .


#8

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'?


#9

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


#10

@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.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLowerCase


#11

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."


#12

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


#13

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


#14

@coremaster49089

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

#15

your code should be like:

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


#16

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


#17

Thank you mikesargsyan


#18

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


#19

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:


#20

I dont know why it does not work