-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtp2q1.html
95 lines (84 loc) · 2.08 KB
/
tp2q1.html
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<!DOCTYPE HTML>
<html>
<head>
<title>Titre principal de la page</title>
<meta charset="utf-8">
<meta name="description" content="165c. uniques">
<style>
table {
border-collapse: collapse;
width: 100%;
}
th,
td {
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #f2f2f2
}
th {
background-color: #4CAF50;
color: white;
}
</style>
</head>
<body>
<div id="page">
<!-- DIV : Aucun sens sémantique - zone géographique -->
<div>
<table id="myTable">
<tr>
<th>Nom</th>
<th>Numéro</th>
</tr>
</table>
</div>
<script>
//noprotect
class Personne {
constructor(nom, numero) {
this.nom = nom;
this.numero = numero;
}
display() {
return "Prénom :" + this.nom + " Numéro :" + this.numero;
}
getNom() {
return this.nom;
}
getNumero() {
return this.numero;
}
}
var saisie = function () {
var tab = [];
while (x !== null && y !== null) {
var x = prompt('Entrez un nom :');
if (x !== null) {
var y = prompt('"Enter un numéro :"');
if (x !== null && y !== null) {
var myObjet = new Personne(x, y);
tab.push(myObjet);
}
}
}
return tab;
}
var affiche = function (tab) {
console.log(tab);
var table = document.getElementById("myTable");
for (let elt of tab) {
console.log(elt.display());
// Create an empty <tr> element and add it to the 1st position of the table:
var row = table.insertRow(-1);
// Insert new cells (<td> elements) at the 1st and 2nd position of the "new" <tr> element:
var cell1 = row.insertCell(0).innerHTML = elt.getNom();
var cell2 = row.insertCell(1).innerHTML = elt.getNumero();
}
}
affiche(saisie());
</script>
</div>
</body>
</html>