Please help me


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

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

search("Jones");
var newFriend = {};
newFriend.firstName = first;
newFriend.lastName = last;
newFriend.email = EMail;
newFriend.phoneNumber = number;

OR your code should look like this:

var newFriend = {
firstName: first,
lastName: last,
email: EMail,
phoneNumber: number;
}
add("Ddawg2005","dogs","(999) 889-6789","ddawg2005@gmail.com")
list()

SyntaxError: Unexpected identifier


#2

Post muli-line code with three backticks (`) on a line above and a line beneath your code. They should be on separate lines from anything else.


#3

what do you mean can you show me ?


#4

To help others read your code, please post your code like this, except without the spaces between the backticks (`).

` ` `
//your code here

` ` `

#5

and where do i put this


#6

Here you go, your code is fixed, please read my comments.

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() {
  for (var i = 0; i < contacts.length; i++) {//there is no such thing as contactsLength, so I replaced it with what you need.
    printPerson(contacts[i]);
  }
}

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

search("Jones");
var newFriend = {};
//everything beneath this was messed up
newFriend.firstName = "first";
newFriend.lastName = "last";
newFriend.email = "EMail";
newFriend.phoneNumber = 0;

EDIT: Are you supposed to have an add function yet?


#7

so i did this code but it still dosent work

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() {
for (var i = 0; i < contacts.length; i++) {//there is no such thing as contactsLength, so I replaced it with what you need.
printPerson(contacts[i]);
}
}
search("Jones");
var newFriend = {};
//everything beneath this was messed up
newFriend.firstName = "first";
newFriend.lastName = "last";
newFriend.email = "EMail";
newFriend.phoneNumber = 0;

ReferenceError: search is not defined

Oops, try again. Make sure that the search() function still exists! Your code threw the following error when checking if you called search(): ReferenceError: search is not defined


#8

Hi the error says that you don't have a function search().


#9

@brandonpreston,
as @wizmarco pointed out your search function is NOT defined anymore.....

and if you want the ADD a new friend you could have used your nicely written add function.....
like

add(""first","last","Email","911");
list();

=================================================

for ([initialization]; [condition]; [final-expression]) {
   statement
}

In your list function you could have expanded your FOR-loop-[initialization]
like

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

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for


#10

You deleted your search function.


#11

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() {
for (var i = 0; i < contacts.length; i++) {//there is no such thing as contactsLength, so I replaced it with what you need.
printPerson(contacts[i]);
}
function search(lastName) {
for(n = 0; contacts.length > n; n++) {
if(contacts[n].lastName == lastName) {
printPerson(contacts[n])

search("Jones");
var newFriend = {};
//everything beneath this was messed up
newFriend.firstName = "first";
newFriend.lastName = "last";
newFriend.email = "EMail";
newFriend.phoneNumber = 0;

SyntaxError: Unexpected end of input


#12

@brandonpreston,

function add(firstName,lastName,email,phoneNumber){
contacts[contacts.length]={
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() {
 for (var i = 0; i < contacts.length; i++) {//there is no such thing as contactsLength,
                               // so I replaced it with what you need.
 printPerson(contacts[i]);
 }
}//close the =list= function

function search(lastName) {
  for(n = 0; contacts.length > n; n++) {
    if(contacts[n].lastName == lastName) {
      printPerson(contacts[n])
    }//close the IF
  }//close the FOR
}//close the FUNCTION
search("Jones");
var newFriend = {};
//everything beneath this was messed up
newFriend.firstName = "first";
newFriend.lastName = "last";
newFriend.email = "EMail";
newFriend.phoneNumber = 0;
console.log(newFriend );
add("first","last","Email","911");
console.log( contacts );

#13

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


#14

@brandonpreston,
updated my post.....


#15

i used it and this is what i get
SyntaxError: missing ) after argument list


#16

@brandonpreston,
Updated post


#17

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,newFriend];

function add(firstName,lastName,email,phoneNumber){
contacts[contacts.legnth]={
firstName :firstName,
lastName : lastName,
phoneNumber : phoneNumber,
email : email
};
}
function printPerson(person) {
console.log(person.firstName + " " + person.lastName);
}

function list() {
for (var i = 0; i < contacts.length; i++) {//there is no such thing as contactsLength,
// so I replaced it with what you need.
printPerson(contacts[i]);
}
}//close the =list= function

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

function list() {
for (var i = 0; i < contacts.length; i++) {//there is no such thing as contactsLength,
// so I replaced it with what you need.
printPerson(contacts[i]);
}
}//close the =list= function

function search(lastName) {
for(n = 0; contacts.length > n; n++) {
if(contacts[n].lastName == lastName) {
printPerson(contacts[n])
}//close the IF
}//close the FOR
}//close the FUNCTION
search("Jones");
var newFriend = {};
//everything beneath this was messed up
newFriend.firstName = "first";
newFriend.lastName = "last";
newFriend.email = "EMail";
newFriend.phoneNumber = 0;
console.log(newFriend );
add("first","last","Email","911");
console.log(contacts);
console.log(list);
Oops, try again. It looks like you didn't log "first last" to the console. Did you remember to call list() after adding your new contact?