mou3az commited on
Commit
13b91f4
1 Parent(s): 81f8e0c

Update templates/quiz.html

Browse files
Files changed (1) hide show
  1. templates/quiz.html +45 -46
templates/quiz.html CHANGED
@@ -48,34 +48,16 @@
48
  a:hover {
49
  text-decoration: underline;
50
  }
51
- .quiz-answer {
52
- margin-top: 10px;
53
- padding: 10px;
54
- background-color: #f9f9f9;
55
- border: 1px solid #ccc;
56
- border-radius: 5px;
57
- }
58
- button {
59
- background-color: #ffc107;
60
- color: #333;
61
- border: none;
62
- padding: 10px 20px;
63
- cursor: pointer;
64
- border-radius: 4px;
65
- margin-top: 20px;
66
- }
67
- button:hover {
68
- background-color: #ffca28;
69
- }
70
  </style>
71
  </head>
72
  <body>
73
  <div class="quiz-container">
74
  <h2>Generated Quiz</h2>
75
- <div id="quizSection"></div>
76
- <button id="submitQuiz" onclick="submitQuiz()">Submit Quiz</button>
77
  </div>
78
- <a href="/" class="generate-link">Back to generate another quiz</a>
 
79
 
80
  <script>
81
  document.addEventListener('DOMContentLoaded', function() {
@@ -83,8 +65,9 @@
83
  });
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,33 +83,39 @@
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}`);
115
- choiceLabel.innerHTML = `${label}: ${choice}`;
116
 
117
  choiceDiv.appendChild(input);
118
  choiceDiv.appendChild(choiceLabel);
 
119
  div.appendChild(choiceDiv);
 
 
 
 
120
  });
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,11 +140,11 @@
151
  }
152
 
153
  if (!answered) {
154
- return false;
155
  }
156
  }
157
 
158
- return true;
159
  }
160
 
161
  function submitQuiz() {
@@ -166,22 +155,32 @@
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>
 
48
  a:hover {
49
  text-decoration: underline;
50
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  </style>
52
  </head>
53
  <body>
54
  <div class="quiz-container">
55
  <h2>Generated Quiz</h2>
56
+ <pre>{{ filtered_text }}</pre>
57
+ <a href="/" class="generate-link">Back to generate another quiz</a>
58
  </div>
59
+ <div id="quizSection"></div>
60
+ <button id="submitQuiz" style="display: none;" onclick="submitQuiz()">Submit Quiz</button>
61
 
62
  <script>
63
  document.addEventListener('DOMContentLoaded', function() {
 
65
  });
66
 
67
  function generateQuiz(filteredText, answersAndExplanations) {
68
+ document.getElementById('inputSection').style.display = 'none';
69
  let quizSection = document.getElementById('quizSection');
70
+ quizSection.innerHTML = '';
71
 
72
  let questions = filteredText.split(/\d+\.\s+/).filter(q => q.trim() !== '');
73
 
 
83
  let choices = choicesText.split(/\s*[A-D]\)\s*/).filter(choice => choice.trim() !== '');
84
  let labels = choicesText.match(/\s*[A-D]\)\s*/g);
85
  choices.forEach((choice, i) => {
86
+ let label = labels[i].trim().charAt(0);
87
 
88
  let choiceDiv = document.createElement('div');
89
 
90
  let input = document.createElement('input');
91
  input.type = 'radio';
92
  input.name = `question_${index + 1}`;
93
+ input.value = label;
94
+ input.id = `q${index + 1}_${label}`;
95
+ input.setAttribute('data-answered', 'false');
96
 
97
  let choiceLabel = document.createElement('label');
98
  choiceLabel.setAttribute('for', `q${index + 1}_${label}`);
99
+ choiceLabel.textContent = `${label}) ${choice}`;
100
 
101
  choiceDiv.appendChild(input);
102
  choiceDiv.appendChild(choiceLabel);
103
+
104
  div.appendChild(choiceDiv);
105
+
106
+ input.addEventListener('change', function() {
107
+ input.setAttribute('data-answered', 'true');
108
+ });
109
  });
110
 
111
  let answerDiv = document.createElement('div');
112
  answerDiv.className = 'quiz-answer';
113
+ answerDiv.style.display = 'none';
114
  div.appendChild(answerDiv);
115
 
116
  let explanationDiv = document.createElement('div');
117
+ explanationDiv.className = 'quiz-explanation';
118
+ explanationDiv.style.display = 'none';
119
  div.appendChild(explanationDiv);
120
 
121
  quizSection.appendChild(div);
 
140
  }
141
 
142
  if (!answered) {
143
+ return false;
144
  }
145
  }
146
 
147
+ return true;
148
  }
149
 
150
  function submitQuiz() {
 
155
 
156
  let quizSection = document.getElementById('quizSection');
157
  let questions = quizSection.getElementsByClassName('quiz-question');
 
 
 
 
 
158
 
159
+ fetch('/process_text', {
160
+ method: 'POST',
161
+ headers: {
162
+ 'Content-Type': 'application/json'
163
+ },
164
+ body: JSON.stringify({ text: "{{ filtered_text }}" })
165
+ })
166
+ .then(response => response.json())
167
+ .then(data => {
168
+ let answersAndExplanations = data.answers_and_explanations;
169
+ for (let i = 0; i < questions.length; i++) {
170
+ let answerDiv = questions[i].querySelector('.quiz-answer');
171
+ let explanationDiv = questions[i].querySelector('.quiz-explanation');
172
+ let answer = answersAndExplanations[i]?.Answer || '';
173
+ let explanation = answersAndExplanations[i]?.Explanation || '';
174
+
175
+ answerDiv.style.display = 'block';
176
+ answerDiv.innerHTML = `Answer: ${answer}`;
177
+
178
+ explanationDiv.style.display = 'block';
179
+ explanationDiv.innerHTML = `Explanation: ${explanation}`;
180
+ }
181
 
182
+ document.getElementById('submitQuiz').style.display = 'none';
183
+ });
184
  }
185
  </script>
186
  </body>