6. We Made a Friend!


#1


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


i stuck

Oops, try again. Make sure that the list() function still exists! Your code threw the following error when checking if you called list(): Error: Line 46: Unexpected token ILLEGAL


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

/*Create a search function
then call it passing "Jones"*/
var search=function(lastname){
    for(var i = 0; i < contacts.length ; i++){
        if(contacts[i].lastName===lastname){
            printPerson(contacts[i])
        }
    }
}
search("Jones")

function add(name,lastname,email,phonenumber){
    this.firstName=name;
    this.lastName=lastname;
    this.email=email;
    this.phoneNumber=phonenumber;
    contacts[contacts.length]=this
}
var mehrad=new add('mehrad','abedi','abedi@yahi.com',0912739123)
list()


#2

I think that phone number should be stored as STRING
Instead of this line:
var mehrad=new add('mehrad','abedi','abedi@yahi.com',0912739123)
try this:
var mehrad=new add('mehrad','abedi','abedi@yahi.com',"0912739123")


#3

put a semicolon after the list function at the last .
like
list();


#4

Hye bro run this 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];

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

/*Create a search function
then call it passing "Jones"*/
function search(lastName){
var contactsLength = contacts.length;
for(var i = 0; i < contactsLength; i++){
//contacts[i];
if(contacts[i].lastName === lastName){
//alert("Yes");
console.log("Yes");
}
}
}
search("Jones");

function add(firstName, lastName, email, phoneNumber){
this.firstName = firstName;
this.lastName = lastName;
this.email = email;
this.phoneNumber = phoneNumber;
contacts[contacts.length]=this
}
/*contacts[contacts.length]= {
add("Ishimdar", "Ahamad", "ishimdar@gma", 121212);
}*/
var mehrad=new add("Ishimdar", "Ahamad", "ishimdar@gma", 121212);
list();


#5

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