Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Instruction:
- We'll be creating a function that allows us to add our new friend to the address book.
- Create a function called add with the parameters firstName, lastName, and email, phoneNumber.
- In this new function, you want to create a new contact object like bob and mary. Instead of having this object's property values be filled with strings though, set them to the appropriate function parameters passed in.
- Add this new contact object to the contacts array.
- Call add with whatever first name, last name, phone number, and email arguments you like.
- Make sure you call the list function, to check if your new entry is added. And delete any other function that logs output in the console, i.e 'search' function.
- Run the 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]);
- }
- }
- function add(firstName, lastName,email, phoneNumber){
- contacts[contacts.length] = {
- firstName: firstName,
- lastName: lastName,
- phoneNumber: phoneNumber,
- email: email
- };
- }
- add("me","u","a@gamail.com",1234344);
- list();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement