JSFiddle - React, Tailwind, and code Playground

by Nicolas PUJOL

JavaScript

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");
}