Created
March 26, 2017 17:49
-
-
Save mickaelandrieu/03549706c21de33b95b3415e3e857c65 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/* | |
Activités : gestion des contacts | |
*/ | |
var Contact = { | |
//initialisation de contact | |
init: function (nom, prenom){ | |
this.nom = nom; | |
this.prenom = prenom; | |
}, | |
// decrire | |
decrire: function(){ | |
return `| ${this.nom} | ${this.prenom} |`; | |
} | |
}; | |
//contact existant | |
var contact1 = Object.create(Contact); | |
contact1.init("Lévisse", "Carole"); | |
var contact2 = Object.create(Contact); | |
contact2.init("Nelsonne", "Mélodie"); | |
function listChoix() | |
{ | |
var menu = ` | |
######## MENU ######### | |
1 : Lister les contacts | |
2 : Ajouter un contact | |
0 : Quitter | |
####################### | |
`; | |
console.log(menu); | |
} | |
function ajouterContact(nom, prenom) | |
{ | |
var newContact = Object.create(Contact); | |
newContact.init(nom, prenom); | |
contacts.push(newContact); | |
console.log("Le nouveau contact à été ajouté."); | |
} | |
function listerContacts(contacts) | |
{ | |
console.log("Voici la liste de vos contacts :"); | |
console.log('| Nom | Prenom |'); | |
contacts.forEach(function(contact){ | |
console.log(`${contact.decrire()}`); | |
}); | |
} | |
console.log("Bienvenue dans le gestionnaire des contacts !"); | |
// var choix = (prompt("Choisissez une option")); | |
var contacts = [contact1, contact2]; | |
var choix; | |
while (choix !== "0"){ | |
listChoix(); | |
choix = prompt("Choisissez une option"); | |
switch(choix) { | |
case "1": | |
listerContacts(contacts) | |
break; | |
case "2": | |
var nom = prompt("Saisissez le nom :"); | |
var prenom = prompt("Saisissez le prénom :"); | |
ajouterContact(nom, prenom); | |
break; | |
default: | |
console.log("Je n'ai pas compris votre choix."); | |
break; | |
} | |
} | |
if (choix === "0"){ | |
console.log("Au revoir !"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment