6/6 missing : after property id


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

var add = function (firstName, lastName, phoneNumber, email) {
contacts[contacts.length] = {
this.firstName: firstName,
this.lastName: lastName,
this.phoneNumber: phoneNumber,
this.email: email
};
};

add ("Gino", "Pino", "029988776655", "gino@ciao.com");

list();

can you help me? i can't understand what i'm missing.


#2

@devjumper30847

Hi there. I believe you have some syntax issues.
Here is my solution. You can compare.

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

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

add ("Nare", "Muradyan", "555-5555", "nm@example.com");
list();

The main problem appears to be in your add function.

Hope this helps.))


#3

thanks. removed "this" and it worked. :hamburger:


#4

Glad it worked. you should probably mark this post as solved then.
Cheers :wink: