-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
196 lines (177 loc) · 5.8 KB
/
Copy pathscript.js
File metadata and controls
196 lines (177 loc) · 5.8 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
// Elementos da UI
const startScreen = document.getElementById('start-screen');
const quizScreen = document.getElementById('quiz-screen');
const resultScreen = document.getElementById('result-screen');
const startButton = document.getElementById('start-button');
const questionText = document.getElementById('question-text');
const currentQuestionSpan = document.getElementById('current-question');
const totalQuestionsSpan = document.getElementById('total-questions');
const answersContainer = document.getElementById('answers-container');
const progressBar = document.getElementById('progress-bar');
const scoreSpan = document.getElementById('score');
const finalScoreSpan = document.getElementById('final-score');
const maxScoreSpan = document.getElementById('max-score');
const resultMessage = document.getElementById('result-message');
const restartButton = document.getElementById('restart-button');
// Perguntas do quiz
const quizQuestions = [
{
question: "Qual é a capital da França?",
answers: [
{ text: "Paris", correct: true },
{ text: "Londres", correct: false },
{ text: "Berlim", correct: false },
{ text: "Madri", correct: false }
]
},
{
question: "Qual é o maior planeta do sistema solar?",
answers: [
{ text: "Terra", correct: false },
{ text: "Júpiter", correct: true },
{ text: "Saturno", correct: false },
{ text: "Marte", correct: false }
]
},
{
question: "Quem escreveu 'Dom Casmurro'?",
answers: [
{ text: "Machado de Assis", correct: true },
{ text: "José de Alencar", correct: false },
{ text: "Clarice Lispector", correct: false },
{ text: "Jorge Amado", correct: false }
]
},
{
question: "Qual é a fórmula química da água?",
answers: [
{ text: "H2O", correct: true },
{ text: "CO2", correct: false },
{ text: "O2", correct: false },
{ text: "NaCl", correct: false }
]
},
{
question: "Qual é o continente mais populoso do mundo?",
answers: [
{ text: "África", correct: false },
{ text: "América", correct: false },
{ text: "Ásia", correct: true },
{ text: "Europa", correct: false }
]
},
{
question: "Qual é o elemento químico com símbolo 'O'?",
answers: [
{ text: "Ouro", correct: false },
{ text: "Oxigênio", correct: true },
{ text: "Ósmio", correct: false },
{ text: "Osmium", correct: false }
]
},
{
question: "Quem pintou a Mona Lisa?",
answers: [
{ text: "Vincent van Gogh", correct: false },
{ text: "Pablo Picasso", correct: false },
{ text: "Leonardo da Vinci", correct: true },
{ text: "Michelangelo", correct: false }
]
},
{
question: "Qual é a capital do Japão?",
answers: [
{ text: "Tóquio", correct: true },
{ text: "Seul", correct: false },
{ text: "Pequim", correct: false },
{ text: "Bangkok", correct: false }
]
}
];
// Estado do quiz
let currentQuestionIndex = 0;
let score = 0;
let answersDisabled = false;
// Inicialização
totalQuestionsSpan.textContent = quizQuestions.length;
maxScoreSpan.textContent = quizQuestions.length;
// Eventos
startButton.addEventListener('click', startQuiz);
restartButton.addEventListener('click', restartQuiz);
// Inicia o quiz
function startQuiz() {
currentQuestionIndex = 0;
score = 0;
scoreSpan.textContent = score;
startScreen.classList.remove('active');
resultScreen.classList.remove('active');
quizScreen.classList.add('active');
showQuestion();
}
// Exibe a pergunta atual
function showQuestion() {
answersDisabled = false;
const currentQuestion = quizQuestions[currentQuestionIndex];
currentQuestionSpan.textContent = currentQuestionIndex + 1;
questionText.textContent = currentQuestion.question;
const progressPercent = (currentQuestionIndex / quizQuestions.length) * 100;
progressBar.style.width = `${progressPercent}%`;
answersContainer.innerHTML = '';
currentQuestion.answers.forEach(answer => {
const button = document.createElement('button');
button.textContent = answer.text;
button.classList.add('answer-btn');
button.dataset.correct = answer.correct;
button.addEventListener('click', selectAnswer);
answersContainer.appendChild(button);
});
}
// Trata a seleção de resposta
function selectAnswer(event) {
if (answersDisabled) return;
answersDisabled = true;
const selectedButton = event.target;
const isCorrect = selectedButton.dataset.correct === 'true';
Array.from(answersContainer.children).forEach(button => {
if (button.dataset.correct === 'true') {
button.classList.add('correct');
} else if (button === selectedButton) {
button.classList.add('incorrect');
}
});
if (isCorrect) {
score++;
scoreSpan.textContent = score;
}
setTimeout(() => {
currentQuestionIndex++;
if (currentQuestionIndex < quizQuestions.length) {
showQuestion();
} else {
showResult();
}
}, 1000);
}
// Mostra o resultado final
function showResult() {
quizScreen.classList.remove('active');
resultScreen.classList.add('active');
finalScoreSpan.textContent = score;
const percentage = (score / quizQuestions.length) * 100;
if (percentage === 100) {
resultMessage.textContent = "Excelente! Você acertou todas as perguntas!";
} else if (percentage >= 80) {
resultMessage.textContent = "Bom trabalho! Você acertou a maioria das perguntas.";
} else if (percentage >= 60) {
resultMessage.textContent = "Você passou, mas ainda pode melhorar.";
} else if (percentage >= 50) {
resultMessage.textContent = "Você está quase lá! Continue praticando.";
} else {
resultMessage.textContent = "Você não passou. Tente novamente!";
}
}
// Reinicia o quiz
function restartQuiz() {
resultScreen.classList.remove('active');
startQuiz();
}