-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
44 lines (34 loc) · 1.19 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
// Axel Cotón Gutiérrez Copyright 2023
let currentColor = '';
let lastColor = '';
function randomColor() {
const colors = ['green', 'orange', 'purple'];
let newColor;
do {
newColor = colors[Math.floor(Math.random() * colors.length)];
} while (newColor === lastColor); // Repetir hasta obtener un color diferente al último
lastColor = newColor; // Actualizar el último color
return newColor;
}
function setColor() {
currentColor = randomColor();
const colorCircle = document.getElementById('color-circle');
colorCircle.style.backgroundColor = currentColor;
}
function checkColor(color) {
const result = document.getElementById('result');
if ((color === 'Verde' && currentColor === 'green') ||
(color === 'Naranja' && currentColor === 'orange') ||
(color === 'Violeta' && currentColor === 'purple')) {
result.innerHTML = '¡Correcto! Buen trabajo.';
result.style.color = "green";
} else {
result.innerHTML = 'Incorrecto. Vuelve a intentarlo.';
result.style.color = "red";
}
}
function nextQuestion() {
setColor();
document.getElementById('result').innerHTML = '';
}
window.onload = setColor;