-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
90 lines (78 loc) · 2.81 KB
/
Copy pathscript.js
File metadata and controls
90 lines (78 loc) · 2.81 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// 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(id +b);
li.classList.add('yellow');
break;
case "blue":
var li = document.getElementById( id + b);
li.classList.add('blue');
break;
case "orange":
var li = document.getElementById(id + b);
li.classList.add('orange');
break;
case "white":
var li = document.getElementById(id + b);
li.classList.add('white');
break;
case "violet":
var li = document.getElementById(id + b );
li.classList.add('violet');
break;
case "fuchsia":
var li = document.getElementById(id + b);
li.classList.add('fuchsia');
break;
}
}
function impeachment(choice) {
for[<0;62;20M
//il me faut un algo qui check si la couleur n'a pas déjà été prise.
//Il faut checker à chaque nouvelle entrée dans le tableau.
//La couleur fait-elle partie du tableau?
}
function c_choice() {
possible_choice = ['green', 'red', 'yellow', 'blue', 'orange', 'white', 'violet', 'fuchsia'];
var computer_choice = [];
var choice = null;
for(var b = 0; b <= 4; b++) {
choice = Math.floor((Math.random() * 6-1) + 1);
computer_choice.push(possible_choice[choice]);
repartition(possible_choice[choice], "solution-", b+1);
}
}
function nice_try() {
c_choice();
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, "li-", i );
tableau_try.push(id);
console.log(tableau_try);
}
};
}
}
window.onload = nice_try;