6/6 We made a friend!


#1

here's 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];

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

};

search("Jones");

function add(firstName, lastName, email, phoneNumber) {
var tyler = ("Tyler" , "Reyes" , "something@something.com" , "911");
};

add(tyler);

but it says that tyler isnt defined. can someone help?


#6 we made a friend
#2

function add(firstName, lastName, email, phoneNumber) {
var tyler = {

firstName: "Tyler",
lastName: "Reyes",
email: "something@something.com",
phoneNumber: "911"

};
contacts[contacts.length] = tyler;
add(tyler);
list(tyler);
};

now I did this and it still says its not defined


#3
function add(firstName, lastName, email, phoneNumber) {
var tyler = ("Tyler" , "Reyes" , "something@something.com" , "911");
};

add(tyler);

We want a function that we can supply data to that will instantiate a new contact object...

var add = function (firstName, lastName, email, phoneNumber) {
    contacts[contacts.length] = {
        firstName: firstName,
        lastName: lastName,
        email: email, 
        phoneNumber: phoneNumber 
    };
};
add("Tyler", "Reyes", "something@something.com", "555-567-9911");
list();

#4

oh. okay. thx! It worked


#5

This helped me a lot. Thank you!


#6

hi?? whats wrong with my code:
var add = function(firsName,lastName,phonenNumber,email){

contacts[contacts.length] = {
    this.firstName: firstName,
    this.lastName: lastName,
    this.phoneNumber: phoneNumber,
    this.email: email
};

};

add("ruddy","ngash",0723445778,"ruddy@ruddys.com");
list();

#7

There is no this in an object literal.


#8

thanks it worked....


#9

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]);
}
var add = function(firstName, lastName, email, phoneNumber) {
contacts[contacts.length] = {
firstName: firstName,
lastName: lastName,
email: email,
phoneNumber: phoneNumber
}
};
add("Lucas", "Barbula", "lucas.barbula@example.com","(555)555-5555");
list ();
getting an unexpected end of input here, not sure what is going on. Have tried the end, pretty much every way possible.


#10

This function is missing a closing RBRACE. This results in 'unexpected end of input' error.


#11

What is an RBRACE ?


#12

An RBRACE is a Right Brace, a closing brace, or closing bracket.


#14

A post was split to a new topic: Problem with the syntax


#15