console.log("Bienvenue dans le gestionnaire des contacts !");
var listeContacts = [{
"nom": "Lévisse",
"prenom": "Carole"
}, {
"nom": "Nelsonne",
"prenom": "Mélodie"
}];
afficherOptions();
var action = "";
while (action !== "0") {
action = prompt("Choisissez une option :");
switch (action) {
case "1":
afficherListeContacts();
break;
case "2":
ajouterContact();
break;
}
}
console.log("\n\nAu revoir !");
function afficherListeContacts() {
console.log("Voici la liste de tous vos contacts :");
for (var i = 0; i < listeContacts.length; i++) {
console.log("Nom : " + listeContacts[i].nom + ", prénom : " + listeContacts[i].prenom);
}
console.log("\n");
afficherOptions();
}
function ajouterContact() {
var nom = "";
var prenom = "";
while (nom === "") {
nom = prompt("Entrez le nom du nouveau contact :");
}
while (prenom === "") {
prenom = prompt("Entrez le prénom du nouveau contact :");
}
listeContacts.push({
"nom": nom,
"prenom": prenom
});
console.log("Le nouveau contact a été ajouté\n\n");
afficherOptions();
}
function afficherOptions() {
console.log("1 : Lister les contacts");
console.log("2 : Ajouter un contact");
console.log("0 : Quitter");
}
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.