-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
99 lines (84 loc) · 2.98 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
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
96
97
98
const answers = [
"Roberto Dinamite", "Romário", "Zico", "Pelé",
"Fred", "Edmundo", "Luis Fabiano",
"Diego Souza", "Ricardo Oliveira", "Túlio Maravilha"
];
const slots = document.querySelectorAll("#slots li");
const input = document.getElementById("guess");
const button = document.getElementById("submit");
const feedback = document.getElementById("feedback");
// Array para controlar respostas corretas
let correctAnswers = Array(10).fill(false);
button.addEventListener("click", () => {
const guess = input.value.trim();
if (guess === "") {
feedback.textContent = "Digite uma resposta!";
feedback.style.color = "red";
return;
}
const index = answers.findIndex(answer =>
answer.toLowerCase() === guess.toLowerCase()
);
if (index !== -1 && !correctAnswers[index]) {
slots[index].textContent = `${index + 1}. ${answers[index]}`;
correctAnswers[index] = true;
feedback.textContent = "Resposta correta!";
feedback.className = "success";
feedback.style.opacity = 1;
feedback.style.color = "green";
// Adicionar um efeito de fade-out após 2 segundos
setTimeout(() => {
feedback.style.opacity = 0;
}, 2000);
} else if (index !== -1) {
feedback.textContent = "Você já acertou essa!";
feedback.style.color = "orange";
} else {
feedback.textContent = "Resposta errada!";
feedback.style.color = "red";
}
input.value = ""; // Limpa o campo de entrada
});
// Opcional: Desativa botão se todas respostas estiverem corretas
button.addEventListener("click", () => {
if (correctAnswers.every(answer => answer)) {
feedback.textContent = "Você completou o Top 10! Parabéns!";
button.disabled = true;
input.disabled = true;
}
});
const progressBar = document.getElementById("progress-bar");
button.addEventListener("click", () => {
const guess = input.value.trim();
if (guess === "") {
showFeedback("Digite uma resposta!", "error");
return;
}
const index = answers.findIndex(answer =>
answer.toLowerCase() === guess.toLowerCase()
);
if (index !== -1 && !correctAnswers[index]) {
slots[index].textContent = `${index + 1}. ${answers[index]}`;
slots[index].classList.add("correct"); // Adiciona a animação de acerto
correctAnswers[index] = true;
updateProgress();
showFeedback("Resposta correta!", "success");
} else if (index !== -1) {
showFeedback("Você já acertou essa!", "warning");
} else {
showFeedback("Resposta errada!", "error");
}
input.value = "";
});
// Atualizar a barra de progresso
function updateProgress() {
const correctCount = correctAnswers.filter(answer => answer).length;
const progress = (correctCount / answers.length) * 100;
progressBar.style.width = `${progress}%`;
}
// Mostrar feedback com animação
function showFeedback(message, type) {
feedback.textContent = message;
feedback.className = type === "success" ? "success show" : type === "error" ? "error show" : "warning show";
setTimeout(() => feedback.classList.remove("show"), 2000);
}