We Made a Friend!


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

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){
var contactsLength = contacts.length;
for(var i=0; i<contacts.length;i++){
if(search === lastName){
printPerson(contacts[i]);
}
}
}

function add(firstName, lastName,phoneNumber, email ) {
contacts[contacts.length] = {

firstName: firstName,
lastName: lastName,
phoneNumber: phoneNumber,
email: email

};
}
add("SOHAIB","ALI",03086198573,"sohaibali451@gmail.com");
list();


#2

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 49: Unexpected token ILLEGAL

this error appears.... Any issue with code?


#3

arguments that you pass to add()function should be string!

hint**
03086198573 is a string ?


#4

thanks its work.... i miss that its a numeric value


#5

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