-
Notifications
You must be signed in to change notification settings - Fork 1
/
quiz.html
356 lines (279 loc) Β· 8.6 KB
/
quiz.html
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
<!DOCTYPE html>
<html>
<head>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Roboto&display=swap" rel="stylesheet">
<!-- satoshi font family -->
<link
href="https://api.fontshare.com/v2/css?f[]=satoshi@1,900,700,500,300,400&display=swap"
rel="stylesheet"
/>
<!-- inter font family -->
<link
href="https://fonts.googleapis.com/css2?family=Inter:wght@100;200;300;400;500;600;700;800;900&display=swap"
rel="stylesheet"
/>
<!-- <link rel="stylesheet" type="text/css" href="style.css"> -->
</head>
<body>
<h1>AI Quiz</h1>
<div id="upload-container">
<textarea id="input-text" placeholder="Enter your text here......"></textarea>
<button id="upload-button" onclick="generateQuiz()">Quiz AI</button>
</div>
<div id="loading-message">Waiting for your input...</div>
<div id ="tab-area"class="tab">
<div id="tab-content-container">
<div id="quiz-container">
<button class="tab-button" id="quiz-btn" value="OFF" onclick="togglequizContent()">Attempt Quiz</button>
<div id="quizcontent" class="tab-content">
<div id="typewriter">
<p id="quiz-para"></p>
</div>
</div>
</div>
</div>
</div>
</body>
<style>
/* style.css */
/* Reset default margin and padding */
body, h1, p {
margin: 25px;
padding: 0;
color: #000000;
}
/* Set background and text color for the page */
body {
background-color: #ff961e;
color: #333;
font-family: 'Satoshi', sans-serif;
}
/* Center align the h1 */
h1 {
margin-top: 5px;
font-size: 60px;
font-weight:800;
line-height: 1.15;
color: #000;
text-align: center;
}
/* Style the tab content */
#tab-content-container {
display: flex;
justify-content: space-evenly;
}
/* Style the tab buttons */
.tab-button {
border: none;
background-color: #5fd4ff;
color: #000000;
padding: 10px 20px;
margin-bottom: 10px;
border-radius: 5px;
font-size: 20px;
cursor: pointer;
outline: none;
transition: background-color 0.3s ease;
}
.tab-button:hover {
background-color: #ffd000;
}
.tab-button.active {
background-color: #0821ff;
}
.tab-content {
background-color: #ffffff;
padding: 20px;
margin-bottom: 20px;
max-width: 500px;
height: auto;
}
/* Show the active tab content */
.tab-content.active {
display: block;
}
#quiz-container{
display: flex;
flex-direction: column;
}
/* make the initail code display hidden */
#quizcontent{
display: none;
border-radius: 10px;
max-width: 500px;
}
#upload-container {
display: flex;
flex-direction: column;
align-items: center;
margin-top: 20px;
margin-bottom: 50px;
}
#input-text {
width: 60%;
height: 250px;
padding: 10px;
font-size: 16px;
border-radius: 5px;
border: 1px solid #ccc;
resize: vertical;
margin-bottom: 10px;
}
#upload-button {
border: none;
background-color: #00bbff;
color: #000000;
padding: 10px 20px;
border-radius: 5px;
font-size: 20px;
cursor: pointer;
outline: none;
}
#upload-button:hover {
background-color: #ffd000;
margin: 5px;
}
.blinking-cursor {
margin-left: 5px;
background-color: #7d7a7a;
animation: blink 1s infinite;
}
#tab-area{
display: none;
}
#loading-message {
text-align: center;
font-size: 30px;
font-weight: bold;
margin-top: 20px;
margin-bottom: 30px;
color: #000000;
}
</style>
<script>
// Get the button and content elements
let quizBtn = document.getElementById("quiz-btn");
let quizcontent = document.getElementById("quizcontent");
let uploadBtn = document.getElementById("upload-button")
let tabArea = document.getElementById("tab-area")
const typewriter = document.getElementById('typewriter');
const quizpara = document.getElementById("quiz-para");
const text = quizpara.textContent;
let inputText = String;
function generateQuiz() {
console.log("generateQuiz called");
var loadingMessage = document.getElementById("loading-message");
var inputText = document.getElementById("input-text").value;
// Array of loading messages
var loadingMessages = [
"Preparing the quiz... π",
"Gathering questions... β",
"Analyzing the subject matter... π§ ",
"Creating engaging quiz content... βοΈ",
"Organizing questions and options... ποΈ",
"Validating quiz structure... β
",
"Adding difficulty levels... βοΈ",
"Reviewing quiz coherence... π",
"Formatting quiz layout... π¨",
"Testing quiz functionality... π§ͺ",
"Refining quiz accuracy... βοΈ",
"Adding final touches... ποΈ",
"Your quiz is ready!... π"
];
// Function to update the loading message with a delayed effect
function updateLoadingMessage(index) {
loadingMessage.textContent = loadingMessages[index];
// Increment the index
index++;
if (index < loadingMessages.length) {
// Call the function recursively after the delay
setTimeout(function() {
updateLoadingMessage(index);
}, 1000);
} else {
// Hide loading message and show tab area
loadingMessage.style.display = "none";
tabArea.style.display = "block";
}
}
// Start updating the loading message
updateLoadingMessage(0);
var xhr = new XMLHttpRequest();
// Set up the request
xhr.open("POST", "/quiz-text", true);
xhr.setRequestHeader("Content-Type", "application/json");
// Define the request payload
var payload = {
text: inputText
};
// Convert the payload to JSON string
var payloadJson = JSON.stringify(payload);
// Set up the event handler for when the response is received
xhr.onreadystatechange = function () {
if (xhr.readyState === 4 && xhr.status === 200) {
var response = JSON.parse(xhr.responseText);
var quiz = response.quiz; // Get the 'summary' property from the response object
var quizcontent = document.getElementById("quizcontent");
var paragraph = document.getElementById("quiz-para"); // Get the existing paragraph element
// Create an introductory message
var questions = quiz.split("\n\n");
var container = document.createElement("div");
// Iterate over each question
for (var i = 0; i < questions.length; i++) {
// Split the question into individual options
var options = questions[i].split("\n");
// Create a container for the question and options
var questionContainer = document.createElement("div");
// Create a <h4> element for the question
var questionHeader = document.createElement("h4");
questionHeader.textContent = options[0];
// Append the question header to the question container
questionContainer.appendChild(questionHeader);
// Iterate over each option and create a radio button
for (var j = 1; j < options.length; j++) {
// Create a <label> element for the option
var optionLabel = document.createElement("label");
// Create a radio button
var radioButton = document.createElement("input");
radioButton.setAttribute("type", "radio");
radioButton.setAttribute("name", "question" + i);
// Create a text node for the option
var optionText = document.createTextNode(options[j]);
// Append the radio button and label to the question container
questionContainer.appendChild(radioButton);
questionContainer.appendChild(optionLabel);
// Append the option text to the label
optionLabel.appendChild(optionText);
// Add a line break after the radio button and option
questionContainer.appendChild(document.createElement("br"));
questionContainer.appendChild(document.createElement("br"));
}
// Append the question container to the main container
container.appendChild(questionContainer);
}
paragraph.appendChild(container);
};
};
// Send the request
xhr.send(payloadJson);
}
window.addEventListener("load",()=>{
function togglequizContent() {
if(quizBtn.value == "OFF"){
quizcontent.style.display = "block";
quizBtn.value = "ON";
}
else if (quizBtn.value == "ON")
{
quizcontent.style.display = "none";
quizBtn.value = "OFF";
}
}
// Function to toggle the display of the expert content
quizBtn.addEventListener("click", togglequizContent);
// uploadBtn.addEventListener("click",generateQuiz);
})
</script>
</html>