JSFiddle - React, Tailwind, and code Playground

by Alex Azuero

JavaScript

var bob = {
    firstName: "Bob",
    lastName: "Jones",
    phoneNumber: "(650) 777-7777",
    email: "[email protected]"
};

var mary = {
    firstName: "Mary",
    lastName: "Johnson",
    phoneNumber: "(650) 888-8888",
    email: "[email protected]"
};

var contacts = [bob, mary]; //array


function printPerson(person) {
    console.log(person.firstName + " " + person.lastName);
     alert(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]);
        };
    };
};


//New function--> to create a new contact object with the function paramters
//Append the new contact object to the contacts array
/*var add = function(firstName, lastName, email, phoneNumber){
var newEntry = {
firstName: firstName,
lastName: lastName,
email: email,
phoneNumber: phoneNumber }
contacts.push(newEntry);
}
*/


var add = function(firstName, lastName, email, phoneNumber){
//Create Array
var newContact= prompt("New Contact Name")
var newEntry  = newContact;
newEntry = {
firstName: firstName,
lastName: lastName,
email: email,
phoneNumber: phoneNumber } //End of Array
//push into contacts the newEntry array
contacts.push(newEntry);

};

add("alex","Azuero","emailtest", "numbertest");
//search("Jones");
list();