-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
61 lines (54 loc) · 1.65 KB
/
script.js
File metadata and controls
61 lines (54 loc) · 1.65 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
let intentos = 6;
let diccionario = ['VOLAR','VUELO', 'AVION','JABON','LAPIZ','VELAR','ZORRO','GUISO','PESAS','LOCOS','VASOS','LUCHA','MARCO','NORMA' ]
const BOTON = document.getElementById("guess-button");
const INPUT = document.getElementById("guess-input");
const VALOR = INPUT.value;
const GRID = document.getElementById("grid");
const PALABRA = diccionario[Math.floor(Math.random() * diccionario.length)];
BOTON.addEventListener("click", intentar);
function intentar() {
const INTENTO = leerIntento();
if (INTENTO === PALABRA) {
terminar("<h1>GANASTE!😀</h1>");
return;
}
const GRID = document.getElementById("grid");
const ROW = document.createElement("div");
ROW.className = "row";
for (let i in PALABRA) {
const SPAN = document.createElement("span");
SPAN.className = "letter";
if (INTENTO[i] === PALABRA[i]) {
//VERDE
SPAN.innerHTML = INTENTO[i];
SPAN.style.backgroundColor = "green";
} else if (PALABRA.includes(INTENTO[i])) {
//AMARILLO
SPAN.innerHTML = INTENTO[i];
SPAN.style.backgroundColor = "yellow";
} else {
//GRIS
SPAN.innerHTML = INTENTO[i];
SPAN.style.backgroundColor = "grey";
}
ROW.appendChild(SPAN);
}
GRID.appendChild(ROW);
intentos--
console.log(intentos);
if (intentos==0){
terminar("PERDISTE!")
}
}
function leerIntento() {
let intento = document.getElementById("guess-input");
intento = intento.value;
intento = intento.toUpperCase();
return intento;
}
function terminar(mensaje) {
INPUT.disabled = true;
BOTON.disabled = true;
let contenedor = document.getElementById("guesses");
contenedor.innerHTML = mensaje;
}