Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
95 lines (83 loc) · 2.66 KB
/
Copy pathscript.js
File metadata and controls
95 lines (83 loc) · 2.66 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
90
91
92
93
94
95
let CardOne = document.querySelector('.card-one');
let CardTwo = document.querySelector('.card-two');
let button = document.querySelector('.button-number');
let circle = document.querySelector('.circle');
const resultados = document.getElementById('result');
let player = [];
let cpu = [];
let num;
const fragmento = document.createDocumentFragment();
//player
for (let i = 0; i < 15; i++) {
let num = Math.random() * 100;
num = Math.round(num);
const span1 = document.createElement('SPAN');
span1.classList.add('spanplayer' + num);
span1.textContent = num;
fragmento.appendChild(span1);
player.push(span1.textContent);
}
CardOne.appendChild(fragmento);
//cpu
for (let i = 0; i < 15; i++) {
let num = Math.random() * 100;
num = Math.round(num);
const span2 = document.createElement('SPAN');
span2.classList.add('spancpu' + num);
span2.textContent = num;
fragmento.appendChild(span2);
cpu.push(span2.textContent);
}
CardTwo.appendChild(fragmento);
button.addEventListener('click',(num) =>{
num = Math.random() * 100;
num = Math.floor(num);
button.textContent = num;
let buttons = document.createElement('BUTTON');
buttons.classList.add('resultadosBingo');
buttons.textContent = num;
resultados.appendChild(buttons);
//eliminar
function eliminar(array, elemento) {
var resultado = []
for (var i = 0; i < array.length; i++) {
if (array[i] !== elemento) {
resultado.push(array[i]);
}
}
return resultado;
}
//eliminar
for(nc of cpu){
let resultadocpu = document.querySelector(`.spancpu${nc}`);
if(nc == num){
resultadocpu.style.background = 'none';
resultadocpu.style.textDecoration = 'line-through'
resultadocpu.style.opacity = '0.5'
cpu = eliminar(cpu,nc)
}
}
for(np of player){
if(np == num){
let resultadoplayer = document.querySelector(`.spanplayer${np}`);
resultadoplayer.style.background = 'none';
resultadoplayer.style.textDecoration = 'line-through';
resultadoplayer.style.opacity = '0.5'
player = eliminar(player,np)
}
}
if(cpu == false && player == false){
alert('el duelo a terminado en un empate')
}else if (cpu == false ){
let writen = document.createElement('P')
writen.classList.add('parrafo')
writen.textContent = 'CPU WINS'
circle.replaceChild(writen,button)
}else if (player == false){
let writen = document.createElement('P')
writen.classList.add('parrafo')
writen.textContent = 'PLAYERS WINS'
circle.replaceChild(writen,button)
}
})
// . text-decoration: line-through