2. More People


#1


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


Oops, try again. Make sure that mary is the second object in contacts

console says: undifined

That's my output why it's not working?


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[1][2]);


#2

why did you create a multi-dimensional array instead of 1d array?

you could simply do:

var contacts = [ bob, mary ]

you nested arrays in the array, bit complicated. For your code you would need contacts[0][0] and contacts[0][1]

with the 1d array you can simply do: contacts[0] and contacts[1]


#3

so what is the line to print in to the screen now? i used: console.log(contacts[1][2]);
but this is not working


#4

if you make the array as it should be, i showed you how to print them:


#5

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[1][0].phoneNumber);

the console shows the number of mary now but i still get an error:
Oops, try again. Make sure that mary is the second object in contacts


#6


#7

you have a multi-dimensional array:

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

while it should be single:

var contacts = [bob, mary];

to access the (wrongly) multi dimensional list:

contacts[0][0]
contacts[0][1]

to access the correct single dimensional list:

contacts[0]
contacts[1]

You could have read all this in my fist answer


#8

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