Bonjour,

voila j'ai un problème, je n'arrive pas à trouver comment obtenir l'écriture des 3 contacts.

pour le troisième contact que je viens de créer j'ai souvent la notification NaN.

merci de m'aider.


Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/* 
Activité : gestion des contacts
*/
 
// TODO : complétez le programme
 
var Contact = {
    // Initialise le contact
    init: function (nom, prenom) {
        this.prenom = prenom;
        this.nom = nom;
    },
 
 
    // Renvoi la description du contact
    decrire: function () {
        var description = "Nom : " + this.nom + ", Prenom : " + this.prenom;
        return description;
    }
};
 
// Création des deux premier contact dans un tableau
var contact1 = Object.create(Contact);
contact1.init("Lévisse", "Carole");
var contact2 = Object.create(Contact);
contact2.init("Nelsonne", "Mélodie");
 
var contact = [contact1, contact2];
 
// Affichage de bienvenu et du choix des options
console.log("Bienvenue dans le gestionnaire de contact !");
console.log("1 : Lister les contacts");
console.log("2 : Ajouter un contact");
console.log("0 : Quittez");
 
var proposition = Number(prompt("Choississez une option :"));
 
// Pour quitez
if (proposition === 0) {
    console.log("Au revoir !");
}
 
// Pour lister les contact
if (proposition === 1) {
    console.log("Voici la liste de tous vos contacts :");
    contact.forEach(function (contact) {
        console.log(contact.decrire());
    });
}
 
// Pour ajouter des contacts
if (proposition === 2) {
    var nouveauNom = Number(prompt("Entrez le nom du nouveau contact :"));
    var nouveauPrenom = Number(prompt("Entrez le prenom du nouveau contact :"));
 
    var nouveauContact = (nouveauNom, nouveauPrenom);
 
 
    contact.push(nouveauContact);
    console.log(contact.length);
    console.log("Le nouveau contact a été ajouté !");
 
 
}