Created
September 5, 2014 21:56
-
-
Save christurnertv/df38f691135b68daeadb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Contact Manager</title> | |
</head> | |
<body> | |
<button id="btnAddContact">Add Contact</button> | |
<script> | |
var contactManager = { | |
"contacts" : [ | |
{ | |
"first_name" : "Chris", | |
"last_initial" : "T" | |
}, | |
{ | |
"first_name" : "Ben", | |
"last_initial" : "B" | |
} | |
], | |
"printNames" : function () { | |
this.contacts.forEach(function (person, index) { | |
console.log(index + ': ' + person.first_name + ' ' + person.last_initial); | |
}); | |
}, | |
"addContact" : function (firstName, lastInitial) { | |
var contact = { | |
"first_name" : firstName, | |
"last_initial" : lastInitial | |
}; | |
this.contacts.push(contact); | |
console.log('Added contact.'); | |
} | |
}; | |
var btnAddContact = document.getElementById('btnAddContact'); | |
btnAddContact.addEventListener('click', function () { | |
var firstName = prompt('Contact First Name:'); | |
var lastInitial = prompt('Contact Last Initial:'); | |
contactManager.addContact(firstName, lastInitial); | |
console.log('===================='); | |
contactManager.printNames(); | |
}); | |
console.log('===================='); | |
contactManager.printNames(); | |
</script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Contact Manager</title> | |
</head> | |
<body> | |
<button id="btnAddContact">Add Contact</button> | |
<script> | |
var contactManager = {}; | |
contactManager.contacts = [ | |
{ | |
"first_name" : "Chris", | |
"last_initial" : "T" | |
}, | |
{ | |
"first_name" : "Ben", | |
"last_initial" : "B" | |
} | |
]; | |
contactManager.printNames = function () { | |
this.contacts.forEach(function (person, index) { | |
console.log(index + ': ' + person.first_name + ' ' + person.last_initial); | |
}); | |
}; | |
contactManager.addContact = function (firstName, lastInitial) { | |
var contact = { | |
"first_name" : firstName, | |
"last_initial" : lastInitial | |
}; | |
this.contacts.push(contact); | |
console.log('Added contact.'); | |
}; | |
var btnAddContact = document.getElementById('btnAddContact'); | |
btnAddContact.addEventListener('click', function () { | |
var firstName = prompt('Contact First Name:'); | |
var lastInitial = prompt('Contact Last Initial:'); | |
contactManager.addContact(firstName, lastInitial); | |
console.log('===================='); | |
contactManager.printNames(); | |
}); | |
console.log('===================='); | |
contactManager.printNames(); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment