Upload index.html
Browse files- templates/index.html +223 -159
templates/index.html
CHANGED
@@ -3,256 +3,320 @@
|
|
3 |
<head>
|
4 |
<meta charset="UTF-8">
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
-
<title>
|
7 |
-
<!-- Inclusion de Tailwind CSS via CDN -->
|
8 |
<script src="https://cdn.tailwindcss.com"></script>
|
9 |
<style>
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
}
|
14 |
-
.
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
}
|
17 |
</style>
|
18 |
</head>
|
19 |
-
<body class="
|
20 |
<div class="container mx-auto mt-8 px-4">
|
21 |
-
<h1 class="text-
|
22 |
|
23 |
<!-- Section de configuration -->
|
24 |
<div class="max-w-2xl mx-auto mb-8">
|
25 |
<div class="bg-white rounded-lg shadow-md p-6">
|
26 |
<div class="mb-4">
|
27 |
<label for="topic" class="block text-sm font-medium text-gray-700 mb-1">Sujet</label>
|
28 |
-
<input type="text" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm" id="topic" placeholder="
|
29 |
</div>
|
30 |
<div class="mb-4">
|
31 |
-
<label class="block text-sm font-medium text-gray-700 mb-2">Type
|
32 |
<div class="flex items-center space-x-4">
|
33 |
<div class="flex items-center">
|
34 |
-
<input id="typeFlashcards" name="contentType" type="radio" value="flashcards" checked class="h-4 w-4 text-indigo-600
|
35 |
-
<label for="typeFlashcards" class="ml-2 block text-sm text-gray-900">
|
36 |
-
Flashcards
|
37 |
-
</label>
|
38 |
</div>
|
39 |
<div class="flex items-center">
|
40 |
-
<input id="typeQuiz" name="contentType" type="radio" value="quiz" class="h-4 w-4 text-indigo-600
|
41 |
-
<label for="typeQuiz" class="ml-2 block text-sm text-gray-900">
|
42 |
-
Quiz
|
43 |
-
</label>
|
44 |
</div>
|
45 |
</div>
|
46 |
</div>
|
47 |
-
<button id="generateBtn" class="w-full py-2 px-4 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-indigo-600 hover:bg-indigo-700
|
48 |
-
|
49 |
</button>
|
50 |
</div>
|
51 |
</div>
|
52 |
|
53 |
<!-- Indicateur de chargement -->
|
54 |
-
<div id="loading" class="hidden text-center my-10
|
55 |
-
|
56 |
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
|
57 |
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
|
58 |
-
|
59 |
-
<p class="mt-2 text-gray-600"
|
60 |
-
</div>
|
61 |
-
|
62 |
-
<!-- Conteneur pour les Flashcards -->
|
63 |
-
<div id="flashcardsContainer" class="mt-6">
|
64 |
-
<!-- Les flashcards seront injectées ici -->
|
65 |
</div>
|
66 |
|
67 |
-
<!-- Conteneur
|
68 |
-
<div id="quizContainer" class="mt-6 max-w-3xl mx-auto">
|
69 |
-
|
|
|
|
|
|
|
70 |
</div>
|
71 |
</div>
|
72 |
|
73 |
<script>
|
74 |
const generateBtn = document.getElementById('generateBtn');
|
75 |
const loadingIndicator = document.getElementById('loading');
|
76 |
-
const flashcardsContainer = document.getElementById('flashcardsContainer');
|
77 |
const quizContainer = document.getElementById('quizContainer');
|
78 |
const topicInput = document.getElementById('topic');
|
|
|
|
|
|
|
79 |
|
80 |
generateBtn.addEventListener('click', function() {
|
81 |
const topic = topicInput.value.trim();
|
82 |
if (!topic) {
|
83 |
-
alert('
|
84 |
return;
|
85 |
}
|
86 |
|
87 |
const contentType = document.querySelector('input[name="contentType"]:checked').value;
|
88 |
-
|
89 |
-
// Afficher le chargement et cacher les anciens résultats
|
90 |
loadingIndicator.classList.remove('hidden');
|
91 |
-
flashcardsContainer.innerHTML = '';
|
92 |
quizContainer.innerHTML = '';
|
93 |
-
flashcardsContainer.classList.add('hidden');
|
94 |
quizContainer.classList.add('hidden');
|
95 |
|
96 |
-
// Envoi de la requête
|
97 |
fetch('/generate', {
|
98 |
method: 'POST',
|
99 |
-
headers: {
|
100 |
-
'Content-Type': 'application/json',
|
101 |
-
},
|
102 |
body: JSON.stringify({ topic, type: contentType }),
|
103 |
})
|
104 |
.then(response => {
|
105 |
-
if (!response.ok) {
|
106 |
-
throw new Error(`Erreur HTTP: ${response.status}`);
|
107 |
-
}
|
108 |
return response.json();
|
109 |
})
|
110 |
.then(data => {
|
111 |
loadingIndicator.classList.add('hidden');
|
112 |
-
|
113 |
if (data.error) {
|
114 |
alert('Erreur: ' + data.error);
|
115 |
return;
|
116 |
}
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
} else if (contentType === 'quiz' && data.quiz) {
|
122 |
quizContainer.classList.remove('hidden');
|
123 |
-
|
124 |
-
} else {
|
125 |
-
alert('Aucune donnée reçue ou format incorrect.');
|
126 |
}
|
127 |
})
|
128 |
.catch(error => {
|
129 |
loadingIndicator.classList.add('hidden');
|
130 |
-
|
131 |
-
alert('Erreur lors de la génération: ' + error.message + '. Vérifiez la console pour plus de détails.');
|
132 |
});
|
133 |
});
|
134 |
|
135 |
-
function
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
140 |
</div>
|
141 |
-
<div class="
|
142 |
-
|
|
|
|
|
143 |
</div>
|
144 |
`;
|
145 |
-
const gridContainer = flashcardsContainer.querySelector('.grid');
|
146 |
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
<strong class="font-bold text-gray-900">Réponse:</strong> ${card.answer}
|
155 |
-
</div>
|
156 |
-
`;
|
157 |
-
gridContainer.appendChild(cardElement);
|
158 |
});
|
159 |
}
|
160 |
|
161 |
-
function
|
162 |
-
const
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
quizContainer.innerHTML = `
|
168 |
-
<div class="mb-4">
|
169 |
-
<h2 class="text-2xl font-semibold text-center text-gray-700 mb-1">Quiz généré (${quizQuestions.length} questions)</h2>
|
170 |
-
<p class="text-center text-gray-500 text-sm">Sélectionnez une réponse pour chaque question</p>
|
171 |
-
</div>
|
172 |
-
`;
|
173 |
-
|
174 |
-
quizQuestions.forEach((question, qIndex) => {
|
175 |
-
const questionElement = document.createElement('div');
|
176 |
-
questionElement.className = 'bg-white rounded-lg shadow p-5 mb-5';
|
177 |
|
178 |
-
|
179 |
-
|
|
|
180 |
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
|
|
|
|
|
|
|
|
190 |
});
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
<strong class="font-bold">Explication:</strong> ${question.explanation}
|
199 |
</div>
|
200 |
`;
|
201 |
-
|
202 |
-
|
|
|
203 |
}
|
204 |
|
205 |
-
function
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
// Vérifier si la question a déjà été répondue
|
211 |
-
let alreadyAnswered = false;
|
212 |
-
questionOptions.forEach(opt => {
|
213 |
-
if (opt.classList.contains('bg-green-100') || opt.classList.contains('bg-red-100')) {
|
214 |
-
alreadyAnswered = true;
|
215 |
-
}
|
216 |
-
});
|
217 |
-
if (alreadyAnswered) return;
|
218 |
-
|
219 |
-
// Réinitialiser les styles des options
|
220 |
-
questionOptions.forEach(option => {
|
221 |
-
option.classList.remove('bg-indigo-100', 'border-indigo-300', 'bg-green-100', 'border-green-300', 'text-green-800', 'bg-red-100', 'border-red-300', 'text-red-800');
|
222 |
-
option.classList.add('hover:bg-gray-100');
|
223 |
-
});
|
224 |
|
225 |
-
|
226 |
-
|
227 |
-
|
|
|
228 |
|
229 |
-
const
|
230 |
-
|
231 |
-
|
232 |
-
|
|
|
|
|
|
|
|
|
233 |
} else {
|
234 |
-
|
235 |
-
element.classList.add('bg-red-100', 'border-red-300', 'text-red-800');
|
236 |
-
|
237 |
-
// Mettre en évidence la bonne réponse
|
238 |
-
questionOptions.forEach(option => {
|
239 |
-
if (option.textContent.trim() === correctAnswer) {
|
240 |
-
option.classList.add('bg-green-100', 'border-green-300', 'text-green-800');
|
241 |
-
option.classList.remove('hover:bg-gray-100');
|
242 |
-
}
|
243 |
-
});
|
244 |
}
|
245 |
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
explanationElement.classList.remove('hidden');
|
255 |
}
|
256 |
</script>
|
257 |
</body>
|
258 |
-
</html>
|
|
|
3 |
<head>
|
4 |
<meta charset="UTF-8">
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<title>Flashcards et Quiz</title>
|
|
|
7 |
<script src="https://cdn.tailwindcss.com"></script>
|
8 |
<style>
|
9 |
+
body {
|
10 |
+
background: linear-gradient(135deg, #1e3a8a, #6b7280);
|
11 |
+
min-height: 100vh;
|
12 |
}
|
13 |
+
.container {
|
14 |
+
background: rgba(255, 255, 255, 0.95);
|
15 |
+
border-radius: 15px;
|
16 |
+
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3);
|
17 |
+
padding: 2rem;
|
18 |
+
}
|
19 |
+
.progress-bar {
|
20 |
+
height: 10px;
|
21 |
+
background: #e5e7eb;
|
22 |
+
border-radius: 5px;
|
23 |
+
overflow: hidden;
|
24 |
+
}
|
25 |
+
.progress-fill {
|
26 |
+
height: 100%;
|
27 |
+
background: linear-gradient(to right, #10b981, #3b82f6);
|
28 |
+
transition: width 0.5s ease-in-out;
|
29 |
+
}
|
30 |
+
.question-card {
|
31 |
+
transform: scale(0.9);
|
32 |
+
opacity: 0;
|
33 |
+
animation: slideIn 0.5s forwards;
|
34 |
+
}
|
35 |
+
@keyframes slideIn {
|
36 |
+
to { transform: scale(1); opacity: 1; }
|
37 |
+
}
|
38 |
+
.correct-answer {
|
39 |
+
animation: correctFlash 0.8s;
|
40 |
+
}
|
41 |
+
.wrong-answer {
|
42 |
+
animation: wrongShake 0.5s;
|
43 |
+
}
|
44 |
+
@keyframes correctFlash {
|
45 |
+
0% { background-color: #10b981; transform: scale(1); }
|
46 |
+
50% { transform: scale(1.05); }
|
47 |
+
100% { background-color: #d1fae5; transform: scale(1); }
|
48 |
+
}
|
49 |
+
@keyframes wrongShake {
|
50 |
+
0%, 100% { transform: translateX(0); }
|
51 |
+
25% { transform: translateX(-10px); }
|
52 |
+
75% { transform: translateX(10px); }
|
53 |
+
}
|
54 |
+
.explanation-container {
|
55 |
+
display: none;
|
56 |
+
margin-top: 1rem;
|
57 |
+
padding: 1rem;
|
58 |
+
background: #f8fafc;
|
59 |
+
border-left: 4px solid #ef4444;
|
60 |
+
border-radius: 5px;
|
61 |
+
animation: slideFromRight 0.5s ease-in-out;
|
62 |
+
}
|
63 |
+
@keyframes slideFromRight {
|
64 |
+
from { transform: translateX(100%); opacity: 0; }
|
65 |
+
to { transform: translateX(0); opacity: 1; }
|
66 |
+
}
|
67 |
+
.character {
|
68 |
+
width: 100px;
|
69 |
+
height: 100px;
|
70 |
+
background: url('chemin/vers/professeur.png') center/contain no-repeat;
|
71 |
+
margin-right: 1rem;
|
72 |
+
}
|
73 |
+
.popup {
|
74 |
+
position: fixed;
|
75 |
+
top: 50%;
|
76 |
+
left: 50%;
|
77 |
+
transform: translate(-50%, -50%) scale(0);
|
78 |
+
background: linear-gradient(135deg, #ffd700, #ff6347);
|
79 |
+
padding: 2rem;
|
80 |
+
border-radius: 15px;
|
81 |
+
box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
|
82 |
+
z-index: 1000;
|
83 |
+
animation: popupIn 0.5s forwards;
|
84 |
+
border: 4px solid #ffd700;
|
85 |
+
color: #fff;
|
86 |
+
}
|
87 |
+
@keyframes popupIn {
|
88 |
+
to { transform: translate(-50%, -50%) scale(1); }
|
89 |
+
}
|
90 |
+
.overlay {
|
91 |
+
position: fixed;
|
92 |
+
top: 0;
|
93 |
+
left: 0;
|
94 |
+
width: 100%;
|
95 |
+
height: 100%;
|
96 |
+
background: rgba(0, 0, 0, 0.7);
|
97 |
+
z-index: 999;
|
98 |
+
}
|
99 |
+
.popup h2 {
|
100 |
+
font-size: 2.5rem;
|
101 |
+
font-weight: bold;
|
102 |
+
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
|
103 |
+
}
|
104 |
+
.popup p {
|
105 |
+
font-size: 1.2rem;
|
106 |
+
margin-top: 1rem;
|
107 |
+
}
|
108 |
+
.popup button {
|
109 |
+
background: #ff4500;
|
110 |
+
border: none;
|
111 |
+
padding: 0.75rem 1.5rem;
|
112 |
+
font-size: 1.1rem;
|
113 |
+
font-weight: bold;
|
114 |
+
border-radius: 10px;
|
115 |
+
transition: transform 0.2s;
|
116 |
+
}
|
117 |
+
.popup button:hover {
|
118 |
+
transform: scale(1.05);
|
119 |
}
|
120 |
</style>
|
121 |
</head>
|
122 |
+
<body class="font-sans">
|
123 |
<div class="container mx-auto mt-8 px-4">
|
124 |
+
<h1 class="text-4xl font-bold text-center text-gray-800 mb-6">Révisons un peu</h1>
|
125 |
|
126 |
<!-- Section de configuration -->
|
127 |
<div class="max-w-2xl mx-auto mb-8">
|
128 |
<div class="bg-white rounded-lg shadow-md p-6">
|
129 |
<div class="mb-4">
|
130 |
<label for="topic" class="block text-sm font-medium text-gray-700 mb-1">Sujet</label>
|
131 |
+
<input type="text" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm p-2" id="topic" placeholder="Balance ton sujet...">
|
132 |
</div>
|
133 |
<div class="mb-4">
|
134 |
+
<label class="block text-sm font-medium text-gray-700 mb-2">Type</label>
|
135 |
<div class="flex items-center space-x-4">
|
136 |
<div class="flex items-center">
|
137 |
+
<input id="typeFlashcards" name="contentType" type="radio" value="flashcards" checked class="h-4 w-4 text-indigo-600">
|
138 |
+
<label for="typeFlashcards" class="ml-2 block text-sm text-gray-900">Flashcards</label>
|
|
|
|
|
139 |
</div>
|
140 |
<div class="flex items-center">
|
141 |
+
<input id="typeQuiz" name="contentType" type="radio" value="quiz" class="h-4 w-4 text-indigo-600">
|
142 |
+
<label for="typeQuiz" class="ml-2 block text-sm text-gray-900">Quiz</label>
|
|
|
|
|
143 |
</div>
|
144 |
</div>
|
145 |
</div>
|
146 |
+
<button id="generateBtn" class="w-full py-2 px-4 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-indigo-600 hover:bg-indigo-700">
|
147 |
+
GO !
|
148 |
</button>
|
149 |
</div>
|
150 |
</div>
|
151 |
|
152 |
<!-- Indicateur de chargement -->
|
153 |
+
<div id="loading" class="hidden text-center my-10">
|
154 |
+
<svg class="animate-spin h-8 w-8 text-indigo-600" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
|
155 |
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
|
156 |
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
|
157 |
+
</svg>
|
158 |
+
<p class="mt-2 text-gray-600">Ça charge, attends deux secs...</p>
|
|
|
|
|
|
|
|
|
|
|
159 |
</div>
|
160 |
|
161 |
+
<!-- Conteneur Quiz -->
|
162 |
+
<div id="quizContainer" class="mt-6 max-w-3xl mx-auto hidden">
|
163 |
+
<div class="progress-bar mb-6">
|
164 |
+
<div class="progress-fill" id="progressFill"></div>
|
165 |
+
</div>
|
166 |
+
<div id="currentQuestion"></div>
|
167 |
</div>
|
168 |
</div>
|
169 |
|
170 |
<script>
|
171 |
const generateBtn = document.getElementById('generateBtn');
|
172 |
const loadingIndicator = document.getElementById('loading');
|
|
|
173 |
const quizContainer = document.getElementById('quizContainer');
|
174 |
const topicInput = document.getElementById('topic');
|
175 |
+
let quizQuestions = [];
|
176 |
+
let currentQuestionIndex = 0;
|
177 |
+
let score = 0;
|
178 |
|
179 |
generateBtn.addEventListener('click', function() {
|
180 |
const topic = topicInput.value.trim();
|
181 |
if (!topic) {
|
182 |
+
alert('Rentre un sujet, bordel !');
|
183 |
return;
|
184 |
}
|
185 |
|
186 |
const contentType = document.querySelector('input[name="contentType"]:checked').value;
|
|
|
|
|
187 |
loadingIndicator.classList.remove('hidden');
|
|
|
188 |
quizContainer.innerHTML = '';
|
|
|
189 |
quizContainer.classList.add('hidden');
|
190 |
|
|
|
191 |
fetch('/generate', {
|
192 |
method: 'POST',
|
193 |
+
headers: { 'Content-Type': 'application/json' },
|
|
|
|
|
194 |
body: JSON.stringify({ topic, type: contentType }),
|
195 |
})
|
196 |
.then(response => {
|
197 |
+
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
|
|
|
|
198 |
return response.json();
|
199 |
})
|
200 |
.then(data => {
|
201 |
loadingIndicator.classList.add('hidden');
|
|
|
202 |
if (data.error) {
|
203 |
alert('Erreur: ' + data.error);
|
204 |
return;
|
205 |
}
|
206 |
+
if (contentType === 'quiz' && data.quiz) {
|
207 |
+
quizQuestions = data.quiz;
|
208 |
+
currentQuestionIndex = 0;
|
209 |
+
score = 0;
|
|
|
210 |
quizContainer.classList.remove('hidden');
|
211 |
+
displayCurrentQuestion();
|
|
|
|
|
212 |
}
|
213 |
})
|
214 |
.catch(error => {
|
215 |
loadingIndicator.classList.add('hidden');
|
216 |
+
alert('Ça a merdé: ' + error.message);
|
|
|
217 |
});
|
218 |
});
|
219 |
|
220 |
+
function displayCurrentQuestion() {
|
221 |
+
if (currentQuestionIndex >= quizQuestions.length) {
|
222 |
+
showResults();
|
223 |
+
return;
|
224 |
+
}
|
225 |
+
|
226 |
+
const question = quizQuestions[currentQuestionIndex];
|
227 |
+
const progress = (currentQuestionIndex / 10) * 100;
|
228 |
+
quizContainer.innerHTML = `
|
229 |
+
<div class="progress-bar mb-6">
|
230 |
+
<div class="progress-fill" id="progressFill" style="width: ${progress}%"></div>
|
231 |
</div>
|
232 |
+
<div class="question-card bg-white rounded-lg shadow-lg p-6">
|
233 |
+
<h5 class="font-semibold text-xl mb-4 text-gray-800">${currentQuestionIndex + 1}. ${question.question}</h5>
|
234 |
+
<div class="options mt-3"></div>
|
235 |
+
<div class="explanation-container" id="explanation-${currentQuestionIndex}"></div>
|
236 |
</div>
|
237 |
`;
|
|
|
238 |
|
239 |
+
const optionsContainer = quizContainer.querySelector('.options');
|
240 |
+
question.options.forEach((option, oIndex) => {
|
241 |
+
const optionElement = document.createElement('div');
|
242 |
+
optionElement.className = 'option block p-3 my-2 border border-gray-200 rounded-md cursor-pointer hover:bg-gray-100 text-gray-800';
|
243 |
+
optionElement.textContent = option;
|
244 |
+
optionElement.onclick = () => selectOption(option, question.correctAnswer, oIndex);
|
245 |
+
optionsContainer.appendChild(optionElement);
|
|
|
|
|
|
|
|
|
246 |
});
|
247 |
}
|
248 |
|
249 |
+
function selectOption(selectedOption, correctAnswer, optionIndex) {
|
250 |
+
const options = quizContainer.querySelectorAll('.option');
|
251 |
+
options.forEach(option => {
|
252 |
+
option.onclick = null;
|
253 |
+
option.classList.remove('cursor-pointer', 'hover:bg-gray-100');
|
254 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
255 |
|
256 |
+
const selectedElement = options[optionIndex];
|
257 |
+
const question = quizQuestions[currentQuestionIndex];
|
258 |
+
const explanationContainer = document.getElementById(`explanation-${currentQuestionIndex}`);
|
259 |
|
260 |
+
if (selectedOption === correctAnswer) {
|
261 |
+
selectedElement.classList.add('correct-answer', 'text-white', 'border-green-500');
|
262 |
+
score++;
|
263 |
+
setTimeout(() => {
|
264 |
+
currentQuestionIndex++;
|
265 |
+
displayCurrentQuestion();
|
266 |
+
}, 1000);
|
267 |
+
} else {
|
268 |
+
selectedElement.classList.add('wrong-answer', 'text-white', 'border-red-500');
|
269 |
+
options.forEach(opt => {
|
270 |
+
if (opt.textContent === correctAnswer) {
|
271 |
+
opt.classList.add('correct-answer', 'text-white', 'border-green-500');
|
272 |
+
}
|
273 |
});
|
274 |
+
explanationContainer.innerHTML = `
|
275 |
+
<div class="flex items-center">
|
276 |
+
<div class="character"></div>
|
277 |
+
<div>
|
278 |
+
<h3 class="text-lg font-semibold mb-2">Explication</h3>
|
279 |
+
<p class="text-sm text-gray-700">${question.explanation}</p>
|
280 |
+
</div>
|
|
|
281 |
</div>
|
282 |
`;
|
283 |
+
explanationContainer.style.display = 'block';
|
284 |
+
document.body.addEventListener('click', proceedToNextQuestion);
|
285 |
+
}
|
286 |
}
|
287 |
|
288 |
+
function proceedToNextQuestion() {
|
289 |
+
document.body.removeEventListener('click', proceedToNextQuestion);
|
290 |
+
currentQuestionIndex++;
|
291 |
+
displayCurrentQuestion();
|
292 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
293 |
|
294 |
+
function showResults() {
|
295 |
+
const overlay = document.createElement('div');
|
296 |
+
overlay.className = 'overlay';
|
297 |
+
document.body.appendChild(overlay);
|
298 |
|
299 |
+
const popup = document.createElement('div');
|
300 |
+
popup.className = 'popup';
|
301 |
+
const percentage = (score / 10) * 100;
|
302 |
+
let suggestion = '';
|
303 |
+
if (percentage < 50) {
|
304 |
+
suggestion = 'Allez du nerf, c’est pas bon.';
|
305 |
+
} else if (percentage < 80) {
|
306 |
+
suggestion = 'Pas mal, mais t’as encore du taf pour tout déchirer.';
|
307 |
} else {
|
308 |
+
suggestion = 'WOW ! Tu gères grave, tu veux essayer un autre sujet ?';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
309 |
}
|
310 |
|
311 |
+
popup.innerHTML = `
|
312 |
+
<h2>Résultats</h2>
|
313 |
+
<p>Score: ${score}/10 (${percentage}%)</p>
|
314 |
+
<p class="mt-2">Détails: ${score} bonnes réponses, ${10 - score} ratées.</p>
|
315 |
+
<p class="mt-4 font-semibold">${suggestion}</p>
|
316 |
+
<button onclick="location.reload()">Rejouer</button>
|
317 |
+
`;
|
318 |
+
document.body.appendChild(popup);
|
|
|
319 |
}
|
320 |
</script>
|
321 |
</body>
|
322 |
+
</html>
|