Update templates/quiz.html
Browse files- templates/quiz.html +25 -33
templates/quiz.html
CHANGED
@@ -84,7 +84,7 @@
|
|
84 |
|
85 |
function generateQuiz(filteredText, answersAndExplanations) {
|
86 |
let quizSection = document.getElementById('quizSection');
|
87 |
-
quizSection.innerHTML = '';
|
88 |
|
89 |
let questions = filteredText.split(/\d+\.\s+/).filter(q => q.trim() !== '');
|
90 |
|
@@ -100,16 +100,15 @@
|
|
100 |
let choices = choicesText.split(/\s*[A-D]\)\s*/).filter(choice => choice.trim() !== '');
|
101 |
let labels = choicesText.match(/\s*[A-D]\)\s*/g);
|
102 |
choices.forEach((choice, i) => {
|
103 |
-
let label = labels[i].trim().charAt(0);
|
104 |
|
105 |
let choiceDiv = document.createElement('div');
|
106 |
|
107 |
let input = document.createElement('input');
|
108 |
input.type = 'radio';
|
109 |
input.name = `question_${index + 1}`;
|
110 |
-
input.value = label;
|
111 |
-
input.id = `q${index + 1}_${label}`;
|
112 |
-
input.setAttribute('data-answered', 'false');
|
113 |
|
114 |
let choiceLabel = document.createElement('label');
|
115 |
choiceLabel.setAttribute('for', `q${index + 1}_${label}`);
|
@@ -122,12 +121,12 @@
|
|
122 |
|
123 |
let answerDiv = document.createElement('div');
|
124 |
answerDiv.className = 'quiz-answer';
|
125 |
-
answerDiv.style.display = 'none';
|
126 |
div.appendChild(answerDiv);
|
127 |
|
128 |
let explanationDiv = document.createElement('div');
|
129 |
explanationDiv.className = 'quiz-answer';
|
130 |
-
explanationDiv.style.display = 'none';
|
131 |
div.appendChild(explanationDiv);
|
132 |
|
133 |
quizSection.appendChild(div);
|
@@ -152,11 +151,11 @@
|
|
152 |
}
|
153 |
|
154 |
if (!answered) {
|
155 |
-
return false;
|
156 |
}
|
157 |
}
|
158 |
|
159 |
-
return true;
|
160 |
}
|
161 |
|
162 |
function submitQuiz() {
|
@@ -166,31 +165,24 @@
|
|
166 |
}
|
167 |
|
168 |
let quizSection = document.getElementById('quizSection');
|
169 |
-
let
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
body: JSON.stringify({ text: "{{ filtered_text }}" })
|
176 |
-
})
|
177 |
-
.then(response => response.json())
|
178 |
-
.then(data => {
|
179 |
-
let answersAndExplanations = data.answersAnd_explanations;
|
180 |
-
for (let i = 0; i < answerDivs.length; i += 2) {
|
181 |
-
let answer = answersAndExplanations[i / 2]?.Answer || '';
|
182 |
-
let explanation = answersAndExplanations[i / 2]?.Explanation || '';
|
183 |
-
|
184 |
-
answerDivs[i].style.display = 'block';
|
185 |
-
answerDivs[i].innerHTML = `Answer: ${answer}`;
|
186 |
-
|
187 |
-
answerDivs[i + 1].style.display = 'block';
|
188 |
-
answerDivs[i + 1].innerHTML = `Explanation: ${explanation}`;
|
189 |
-
}
|
190 |
|
191 |
-
|
192 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
193 |
}
|
194 |
</script>
|
195 |
</body>
|
196 |
-
</html>
|
|
|
84 |
|
85 |
function generateQuiz(filteredText, answersAndExplanations) {
|
86 |
let quizSection = document.getElementById('quizSection');
|
87 |
+
quizSection.innerHTML = '';
|
88 |
|
89 |
let questions = filteredText.split(/\d+\.\s+/).filter(q => q.trim() !== '');
|
90 |
|
|
|
100 |
let choices = choicesText.split(/\s*[A-D]\)\s*/).filter(choice => choice.trim() !== '');
|
101 |
let labels = choicesText.match(/\s*[A-D]\)\s*/g);
|
102 |
choices.forEach((choice, i) => {
|
103 |
+
let label = labels[i].trim().charAt(0);
|
104 |
|
105 |
let choiceDiv = document.createElement('div');
|
106 |
|
107 |
let input = document.createElement('input');
|
108 |
input.type = 'radio';
|
109 |
input.name = `question_${index + 1}`;
|
110 |
+
input.value = label;
|
111 |
+
input.id = `q${index + 1}_${label}`;
|
|
|
112 |
|
113 |
let choiceLabel = document.createElement('label');
|
114 |
choiceLabel.setAttribute('for', `q${index + 1}_${label}`);
|
|
|
121 |
|
122 |
let answerDiv = document.createElement('div');
|
123 |
answerDiv.className = 'quiz-answer';
|
124 |
+
answerDiv.style.display = 'none';
|
125 |
div.appendChild(answerDiv);
|
126 |
|
127 |
let explanationDiv = document.createElement('div');
|
128 |
explanationDiv.className = 'quiz-answer';
|
129 |
+
explanationDiv.style.display = 'none';
|
130 |
div.appendChild(explanationDiv);
|
131 |
|
132 |
quizSection.appendChild(div);
|
|
|
151 |
}
|
152 |
|
153 |
if (!answered) {
|
154 |
+
return false;
|
155 |
}
|
156 |
}
|
157 |
|
158 |
+
return true;
|
159 |
}
|
160 |
|
161 |
function submitQuiz() {
|
|
|
165 |
}
|
166 |
|
167 |
let quizSection = document.getElementById('quizSection');
|
168 |
+
let questions = quizSection.getElementsByClassName('quiz-question');
|
169 |
+
let answersAndExplanations = {{ answers_and_explanations | tojson }};
|
170 |
+
|
171 |
+
for (let i = 0; i < questions.length; i++) {
|
172 |
+
let answer = answersAndExplanations[i]?.Answer || '';
|
173 |
+
let explanation = answersAndExplanations[i]?.Explanation || '';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
174 |
|
175 |
+
let answerDiv = questions[i].querySelector('.quiz-answer:nth-of-type(1)');
|
176 |
+
answerDiv.style.display = 'block';
|
177 |
+
answerDiv.innerHTML = `Answer: ${answer}`;
|
178 |
+
|
179 |
+
let explanationDiv = questions[i].querySelector('.quiz-answer:nth-of-type(2)');
|
180 |
+
explanationDiv.style.display = 'block';
|
181 |
+
explanationDiv.innerHTML = `Explanation: ${explanation}`;
|
182 |
+
}
|
183 |
+
|
184 |
+
document.getElementById('submitQuiz').style.display = 'none';
|
185 |
}
|
186 |
</script>
|
187 |
</body>
|
188 |
+
</html>
|