2.More People (help please!)


#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 = (contacts[1].phoneNumber);

This is my code which prints out Mary's number, but I then receive the "Oops, try again. Did you remember to print out mary's phone number?" message.

Looking at other messages some people suggest not using "=" for the console.log, but if I try that I get "TypeError: console.log is not a function."

Grateful for any thoughts!


#2

Remove the = from console.log() and try again look at the output box if it's giving any error post it here.


#3

When I use

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

the output box reads

"(650) 888-8888"

whereas if I use

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

the output box reads

TypeError: console.log is not a function. (In 'console.log(contacts[1].phoneNumber)', 'console.log' is "(650) 888-8888")


#4

I made object like your and printed with console.log and console.log= both worked for some reason I don't if that's a glitch or not on your side.


#5

Just refreshed the browser which seems to solve it. Thanks!


#6

Yep it was a bug then.


#7

the error message saying did you forget to print mary's name and this is the 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"
};
var contacts =[bob, mary]
console.log = (contacts[1].phoneNumber);


#8

Look at your last line it says
console.log = (contacts[1].phoneNumber);
change phoneNumber to firstName


#9

100% 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].phoneNumber);


#10

it does not, sorry. At least not anymore.


#11

This is my 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[1].phoneNumber);

It prints out the correct number and I get the error: Oops, try again. Did you remember to print out mary's phone number?
Which I believe to be able to truthfully answer with yes.
What am I doing wrong here?

Also btw. they always speak of arrays when speaking of bob and mary but aren't they objects?
Only var contacts is an array. At least from what I remember what this site teached me.