-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
46 lines (36 loc) · 1.29 KB
/
script.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
// Axel Cotón Gutiérrez Copyright 2023
const colores = ['red', 'yellow', 'blue']; // Nombres en inglés
const mezclas = {
'redyellow': 'orange',
'yellowred': 'orange',
'redblue': 'purple',
'bluered': 'purple',
'blueyellow': 'green',
'yellowblue': 'green'
};
let color1, color2, mezclaCorrecta;
function seleccionarColores() {
color1 = colores[Math.floor(Math.random() * colores.length)];
do {
color2 = colores[Math.floor(Math.random() * colores.length)];
} while (color2 === color1); // Repite hasta que color2 sea diferente de color1
mezclaCorrecta = mezclas[color1 + color2];
document.getElementById('color-circle-1').style.backgroundColor = color1;
document.getElementById('color-circle-2').style.backgroundColor = color2;
}
function checkColor(colorSeleccionado) {
const result = document.getElementById('result');
if (colorSeleccionado === mezclaCorrecta) {
result.innerHTML = '¡Correcto! Buen trabajo.';
result.style.color = "green";
} else {
result.innerHTML = 'Incorrecto. Vuelve a intentarlo.';
result.style.color = "red";
}
}
function nextQuestion() {
seleccionarColores();
document.getElementById('result').innerText = '';
}
// Inicializar el primer juego
seleccionarColores();