-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
164 lines (129 loc) · 5.19 KB
/
main.js
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
let palabras = [
"pepino",
"tomate",
"alura",
"diente",
"cerveza",
"galleta",
"platano",
"computador",
"comida",
"software",
"spiderman",
"vengador",
"camisa",
"pelicula",
"cabeza",
"pantalon",
"bailar"
];
let guardado = localStorage.getItem('datos');
if (guardado != "") {
palabras = palabras.concat(JSON.parse(guardado));
console.log(palabras, "guardas")
}
let reset = false;
let correcto = 0;
let incorrecto = 0;
let palabrasuser = [];
let aleatorio = Math.floor(Math.random() * (palabras.length));
let seleccion = palabras[aleatorio]
let array1 = seleccion.split('');
let array = array1.reverse();
console.log("trace(seleccion)", array)
for (let index = 0; index < array.length; index++) {
const element = array[index];
document.getElementById('form').insertAdjacentHTML('afterbegin', `<img src="img/img.png" alt="" class="icos" id="img_${element}" name="img_${element}" value="${element}"/>`)
}
let Form = document.getElementById("btna");
Form.addEventListener("submit", function (event) {
event.preventDefault();
});
function jugar(params) {
document.getElementById('formhome').style.display = "none";
document.getElementById('form').style.display = "";
document.getElementById('formperdiste').style.display = "none";
document.getElementById('formganaste').style.display = "none";
}
function home(params) {
document.getElementById('form').style.display = "none";
document.getElementById('formhome').style.display = "";
document.getElementById('formadd').style.display = "none";
document.getElementById('formperdiste').style.display = "none";
document.getElementById('formganaste').style.display = "none";
}
function palabra(params) {
document.getElementById('form').style.display = "none";
document.getElementById('formhome').style.display = "none";
document.getElementById('formadd').style.display = "";
document.getElementById('formperdiste').style.display = "none";
document.getElementById('formganaste').style.display = "none";
}
function guardar() {
let texto = document.getElementById('texto').value;
if (texto == "") {
document.getElementById('oculto4').style.display = "";
setTimeout(function () {
document.getElementById('oculto4').style.display = "none";
}, 2000);
} else {
palabrasuser.push(texto);
console.log(palabrasuser);
document.getElementById('oculto3').style.display = "";
setTimeout(function () {
document.getElementById('oculto3').style.display = "none";
}, 1000);
}
// document.getElementById("texto").reset();
document.getElementById('texto').value = "";
document.getElementById('texto').setAttribute("value", "");
localStorage.setItem('datos', JSON.stringify(palabrasuser));
return false; // stop submission
}
function f_a(letra) { // let a = document.getElementById("btna").value;
let resultado2 = array.filter(x => x.toLowerCase().includes(letra));
// const resultado2 = array.find(array => array == 'a');
console.log("clicka", resultado2)
if (array.length == 1) {
document.getElementById('formganaste').style.display = "";
document.getElementById('form').style.display = "none";
document.getElementById('formperdiste').style.display = "none";
}
if (resultado2.length < 1) {
incorrecto = incorrecto + 1;
document.getElementById("img").src = "img/ahorcado" + incorrecto + ".png";
// document.getElementById('btn' + letra).style.visibility = 'hidden';
document.getElementById('btn' + letra).setAttribute("disabled", "disabled");
if (array.length < incorrecto) {
document.getElementById('oculto2').style.display = "";
document.getElementById('form').style.display = "none";
document.getElementById('formperdiste').style.display = "";
document.getElementById("img").src = "img/ahorcado.png";
document.getElementById('palabra').setAttribute("value", seleccion);
}
} else {
for (let index = 0; resultado2.length; index++) {
let btn = document.createElement('img')
btn.src = 'img/' + letra + '.png';
btn.className = 'icos';
let quita = document.getElementById("form");
let pone = document.getElementById("img_" + letra);
pone = document.getElementById("img_" + letra);
quita.replaceChild(btn, pone);
document.getElementById('btn' + letra).setAttribute("style", "background-color: #e600b0;");
document.getElementById('btn' + letra).setAttribute("disabled", "disabled");
correcto = correcto + 1;
// incorrecto = incorrecto - 1;
array = array.filter(function (f) {
return f !== letra;
})
}
}
}
function pintar(letra) {
document.getElementById('btna').setAttribute("style", "background-color: #e600b0;");
document.getElementById('btna').setAttribute("disabled", "disabled");
document.getElementsByName("btna").className = 'morado';
document.getElementById("btna").style.display = "none";
console.log("morado")
}