-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
77 lines (61 loc) · 1.95 KB
/
script.js
File metadata and controls
77 lines (61 loc) · 1.95 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
let intentos = 6
let diccionario = ['APPLE', 'HURLS', 'WINGS', 'YOUTH']
const palabra = diccionario[Math.floor(Math.random() * diccionario.length)];
const button = document.getElementById("guess-button")
window.addEventListener('load', init)
button.addEventListener("click", intenar)
function intenar(){
const INTENTO = leerIntento();
const regex = /\d/
if(INTENTO === palabra){
terminar("<h1>GANASTE! :)</h1>")
}
else if (regex.test(INTENTO)){
alert("Solo letras sin numeros")
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';
SPAN.style.width ="50px"
SPAN.style.height= "50px"
SPAN.style.borderRadius = '5px'
if (INTENTO[i]===palabra[i]){
SPAN.innerHTML = INTENTO[i];
SPAN.style.backgroundColor = 'green';
} else if( palabra.includes(INTENTO[i]) ) {
SPAN.innerHTML = INTENTO[i];
SPAN.style.backgroundColor = 'yellow';
} else {
SPAN.innerHTML = INTENTO[i];
SPAN.style.backgroundColor = 'grey';
}
ROW.appendChild(SPAN)
}
GRID.appendChild(ROW)
intentos--
if (intentos==0){
terminar("<h1>PERDISTE!</h1>")
}
}
function terminar(mensaje){
const INPUT = document.getElementById("guess-input")
const button = document.getElementById("guess-button")
INPUT.disabled = true
button.disabled = true;
let contenedor = document.getElementById("guesses")
contenedor.innerHTML = mensaje
}
function leerIntento(){
let intento = document.getElementById("guess-input")
intento = intento.value
intento = intento.toUpperCase()
return intento
}
function init(){
console.log('Esto se ejecuta solo cuando se carga la pagina web')
console.log(palabra)
}