-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path$
More file actions
75 lines (71 loc) · 2.54 KB
/
Copy path$
File metadata and controls
75 lines (71 loc) · 2.54 KB
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
// fonction tableau_try //
// Lorsqu'on clique sur un élément de la liste du choix des couleurs,
// je veux que ça créé un élément d'une liste avec une classe couleur qu'on met
// dans un tableau pour la comparaison.
//
//
function repartition(expression, id, b) {
switch (expression) {
case "green":
var li = document.getElementById(id + b);
li.classList.add('green');
break;
case "red":
var li = document.getElementById(id + b);
li.classList.add('red');
break;
case "yellow":
var li = document.getElementById('li-'+b);
li.classList.add('yellow');
break;
case "blue":
var li = document.getElementById('li-'+b);
li.classList.add('blue');
break;
case "orange":
var li = document.getElementById('li-'+b);
li.classList.add('orange');
break;
case "white":
var li = document.getElementById('li-'+b);
li.classList.add('white');
break;
case "violet":
var li = document.getElementById('li-'+b );
li.classList.add('violet');
break;
case "fuchsia":
var li = document.getElementById('li-'+b);
li.classList.add('fuchsia');
break;
}
}
function c_choice() {
possible_choice = ['green', 'red', 'yellow', 'blue', 'orange', 'white', 'violet', 'fuchsia'];
var computer_choice = [];
var choice = null;
for(var b = 0; b <= 3; b++) {
choice = Math.floor((Math.random() * 6-1) + 1);
computer_choice.push(possible_choice[choice]);
repartition(possible_choice[choice], b);
}
}
function nice_try() {
var tableau_try =[];
var colors = [];
var color_list = ['green', 'red', 'yellow', 'blue', 'orange', 'white', 'violet', 'fuchsia'];
for(var i = 0; i <= color_list.length-1; i++) {
colors.push(document.getElementById(color_list[i]));
// La boucle for n'attend pas la réalisation de l'évènement. Peut
// déclencher une erreur.
// Regarder Boucle closure.
colors[i].onclick = function(ev) {
if(tableau_try.length < 4) {
repartition(ev.target.id);
tableau_try.push(ev.target.id);
console.log(tableau_try);
}
};
}
}
window.onload = nice_try;