We Made a Friend SOLVED


#1


THIS IS MY ERROR MESSAGE!


#2

Is there something that you would like to ask?

That error message seems to be suggesting to add some more contacts, what are your thoughts around that? If you want to know something, you'll have to ask for it.


#3

@haxor789 any thoughts I'm stuck its say i only have two contacts in the array


#4

this exercise is complete yet the code has an error i added the add function and called add below


#5

Could you post copyable and formatted code, please?


Also what is the exercise this is referring to?
So far there should be 3 objects in contacts.
Refreshed the page?


#6

That doesn't explain what you want to know, what you expect or what you have tried so far. It's like screaming that you have a giant lime green rubber duck. Great. Not sure why I need to know about that though.

What do you want to know?


#7

my code won't run are you able to point out what its missing
thanks


#8

we made friend / building an address book
function add(firstName,lastName,email,phoneNumber){
contacts[contacts.legnth]={
firstName :firstName,
lastName : lastName,
email : email,
phoneNumber : phoneNumber
}
}
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];

function printPerson(person) {
console.log(person.firstName + " " + person.lastName);
}

function list() {
var contactsLength = contacts.length;
for (var i = 0; i < contactsLength; i++) {
printPerson(contacts[i]);
}
}
function search(lastName){
contactsLength = contacts.length;
for(var i= 0; i < contactsLength; i++) {
if (contacts[i].lastName == lastName){
printPerson(contacts[i]);
}
}
}

/*Create a search function
then call it passing "Jones"*/
add("jon","smith","yesbae@me.com",777-666-8888);
list();


#9

Isn't your error message already doing that?

If not, in what way isn't it?


#10

thank you i solved it was a miss spelled word
contacts.legnth


#11

Just got to the same result. In case you experience something like this extensively use console.log. console.log the contacts array before after and during the adding and everywhere you think something should change until you get it. :slightly_smiling:

PS: Also pretty interesting how arrays handle that square bracket notation for non-number indices.


#12

i used the same code but i get this

Oops, try again. It looks like there are still only two items in the contacts array.