Update templates/quiz.html
Browse files- templates/quiz.html +12 -7
templates/quiz.html
CHANGED
@@ -63,15 +63,15 @@
|
|
63 |
<script>
|
64 |
// Use the passed response JSON directly
|
65 |
let textWithAnswers = `{{ textWithAnswers|tojson|safe }}`;
|
66 |
-
console.log('textWithAnswers:', textWithAnswers);
|
67 |
-
|
68 |
window.onload = function() {
|
|
|
69 |
generateQuiz();
|
70 |
};
|
71 |
|
72 |
-
function
|
73 |
let lines = text.split(/\n+/);
|
74 |
let filteredLines = [];
|
|
|
75 |
let answersAndExplanations = [];
|
76 |
|
77 |
lines.forEach(line => {
|
@@ -79,6 +79,7 @@
|
|
79 |
|
80 |
if (line.startsWith("Question:")) {
|
81 |
filteredLines.push(line);
|
|
|
82 |
} else if (line.startsWith("Choices:")) {
|
83 |
filteredLines.push(line);
|
84 |
} else if (line.startsWith("Answer:")) {
|
@@ -97,6 +98,8 @@
|
|
97 |
|
98 |
let filteredText = filteredLines.join("\n");
|
99 |
|
|
|
|
|
100 |
return {
|
101 |
filteredText: filteredText,
|
102 |
answersAndExplanations: answersAndExplanations
|
@@ -104,8 +107,10 @@
|
|
104 |
}
|
105 |
|
106 |
function generateQuiz() {
|
107 |
-
let quizText =
|
108 |
-
let { filteredText, answersAndExplanations } =
|
|
|
|
|
109 |
|
110 |
let quizSection = document.getElementById('quizSection');
|
111 |
quizSection.innerHTML = '';
|
@@ -196,8 +201,8 @@
|
|
196 |
|
197 |
let quizSection = document.getElementById('quizSection');
|
198 |
let answerDivs = quizSection.getElementsByClassName('quiz-answer');
|
199 |
-
let quizText =
|
200 |
-
let { filteredText, answersAndExplanations } =
|
201 |
|
202 |
for (let i = 0; i < answerDivs.length; i += 2) {
|
203 |
let answer = answersAndExplanations[i / 2]?.Answer || '';
|
|
|
63 |
<script>
|
64 |
// Use the passed response JSON directly
|
65 |
let textWithAnswers = `{{ textWithAnswers|tojson|safe }}`;
|
|
|
|
|
66 |
window.onload = function() {
|
67 |
+
document.getElementById('quizText').value = textWithAnswers;
|
68 |
generateQuiz();
|
69 |
};
|
70 |
|
71 |
+
function handletext(text) {
|
72 |
let lines = text.split(/\n+/);
|
73 |
let filteredLines = [];
|
74 |
+
let questionCount = 0;
|
75 |
let answersAndExplanations = [];
|
76 |
|
77 |
lines.forEach(line => {
|
|
|
79 |
|
80 |
if (line.startsWith("Question:")) {
|
81 |
filteredLines.push(line);
|
82 |
+
questionCount++;
|
83 |
} else if (line.startsWith("Choices:")) {
|
84 |
filteredLines.push(line);
|
85 |
} else if (line.startsWith("Answer:")) {
|
|
|
98 |
|
99 |
let filteredText = filteredLines.join("\n");
|
100 |
|
101 |
+
console.log(filteredText);
|
102 |
+
|
103 |
return {
|
104 |
filteredText: filteredText,
|
105 |
answersAndExplanations: answersAndExplanations
|
|
|
107 |
}
|
108 |
|
109 |
function generateQuiz() {
|
110 |
+
let quizText = document.getElementById('quizText').value;
|
111 |
+
let { filteredText, answersAndExplanations } = handletext(quizText);
|
112 |
+
|
113 |
+
document.getElementById('inputSection').style.display = 'none';
|
114 |
|
115 |
let quizSection = document.getElementById('quizSection');
|
116 |
quizSection.innerHTML = '';
|
|
|
201 |
|
202 |
let quizSection = document.getElementById('quizSection');
|
203 |
let answerDivs = quizSection.getElementsByClassName('quiz-answer');
|
204 |
+
let quizText = document.getElementById('quizText').value;
|
205 |
+
let { filteredText, answersAndExplanations } = handletext(quizText);
|
206 |
|
207 |
for (let i = 0; i < answerDivs.length; i += 2) {
|
208 |
let answer = answersAndExplanations[i / 2]?.Answer || '';
|