Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <title>Lab 3</title>
- </head>
- <body>
- <h1 id="headline">Hello...</h1>
- <script>
- var contactList = [];
- var build = function(firstName, lastName, emailAddr) {
- contactList.push({
- first : firstName,
- last : lastName,
- email : emailAddr
- });
- };
- var edit = function(contact) {
- var newEmail = prompt("Enter new email");
- if (newEmail)
- contact.email = newEmail;
- };
- var find = function(lastname) {
- for (var i=0; i<contactList.length; i++)
- if (contactList[i].last == lastname)
- return contactList[i];
- };
- var remove = function(contact) {
- for (var i=0; i<contactList.length; i++)
- if (contactList[i] == contact)
- contactList.splice(i, 1);
- };
- var test = function() {
- build("Joe1", "Smith1", "joe1@gmail.com");
- build("Joe2", "Smith2", "joe2@gmail.com");
- build("Joe3", "Smith3", "joe3@gmail.com");
- build("Joe4", "Smith4", "joe4@gmail.com");
- console.log(contactList);
- edit(contactList[1]); //Joe2
- console.log(contactList[1]);
- var contact = find("Smith3");
- remove(contact);
- console.log(contactList);
- };
- </script>
- </body>
- </html>
Add Comment
Please, Sign In to add comment