Drew4564 commited on
Commit
a64558d
Β·
verified Β·
1 Parent(s): 5db9dce

add a red border on exam page like when taking an exam like a square where the exam is inside and the exam should be one question then move tio other not alow of numbers in one page every answer next page

Browse files
Files changed (2) hide show
  1. app.js +57 -7
  2. index.html +9 -4
app.js CHANGED
@@ -207,13 +207,13 @@ function renderExamList() {
207
  });
208
  });
209
  }
210
-
211
  // Start an exam
212
  function startExam(examId) {
213
  const exam = state.exams.find(e => e.id === examId);
214
  if (!exam) return;
215
 
216
  state.currentExam = exam;
 
217
  state.examStartTime = new Date();
218
  state.suspiciousActivities = 0;
219
 
@@ -221,9 +221,9 @@ function startExam(examId) {
221
  examTitle.textContent = exam.subject;
222
  examQuestions.innerHTML = '';
223
 
224
- // Render questions
225
- exam.questions.forEach((q, index) => {
226
- const questionCard = document.createElement('div');
227
  questionCard.className = 'question-card bg-white rounded-xl shadow-sm p-4';
228
 
229
  if (q.type === 'multiple') {
@@ -245,12 +245,62 @@ function startExam(examId) {
245
  class="w-full px-4 py-2 border border-gray-300 rounded-lg">
246
  `;
247
  }
248
-
249
- examQuestions.appendChild(questionCard);
 
 
 
 
 
 
 
 
 
 
 
 
 
250
  });
 
 
 
 
251
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
252
  // Start timer
253
- const durationInSeconds = exam.duration * 60;
254
  let remainingTime = durationInSeconds;
255
 
256
  updateTimerDisplay(remainingTime);
 
207
  });
208
  });
209
  }
 
210
  // Start an exam
211
  function startExam(examId) {
212
  const exam = state.exams.find(e => e.id === examId);
213
  if (!exam) return;
214
 
215
  state.currentExam = exam;
216
+ state.currentQuestionIndex = 0;
217
  state.examStartTime = new Date();
218
  state.suspiciousActivities = 0;
219
 
 
221
  examTitle.textContent = exam.subject;
222
  examQuestions.innerHTML = '';
223
 
224
+ // Render first question
225
+ renderQuestion(0);
226
+ const questionCard = document.createElement('div');
227
  questionCard.className = 'question-card bg-white rounded-xl shadow-sm p-4';
228
 
229
  if (q.type === 'multiple') {
 
245
  class="w-full px-4 py-2 border border-gray-300 rounded-lg">
246
  `;
247
  }
248
+ // Add event listeners for navigation
249
+ document.getElementById('prev-question').addEventListener('click', () => {
250
+ if (state.currentQuestionIndex > 0) {
251
+ state.currentQuestionIndex--;
252
+ renderQuestion(state.currentQuestionIndex);
253
+ }
254
+ });
255
+
256
+ document.getElementById('next-question').addEventListener('click', () => {
257
+ if (state.currentQuestionIndex < state.currentExam.questions.length - 1) {
258
+ state.currentQuestionIndex++;
259
+ renderQuestion(state.currentQuestionIndex);
260
+ } else {
261
+ submitExam();
262
+ }
263
  });
264
+ // Render a single question
265
+ function renderQuestion(index) {
266
+ const question = state.currentExam.questions[index];
267
+ examQuestions.innerHTML = '';
268
 
269
+ const questionCard = document.createElement('div');
270
+ questionCard.className = 'question-card';
271
+
272
+ if (question.type === 'multiple') {
273
+ questionCard.innerHTML = `
274
+ <h4 class="font-medium mb-3">${index + 1}. ${question.text}</h4>
275
+ <div class="space-y-2">
276
+ ${question.options.map((opt, i) => `
277
+ <label class="flex items-center space-x-3 cursor-pointer">
278
+ <input type="radio" name="q${question.id}" value="${i}" class="w-4 h-4 text-indigo-600">
279
+ <span>${opt}</span>
280
+ </label>
281
+ `).join('')}
282
+ </div>
283
+ `;
284
+ } else {
285
+ questionCard.innerHTML = `
286
+ <h4 class="font-medium mb-3">${index + 1}. ${question.text}</h4>
287
+ <input type="text" name="q${question.id}"
288
+ class="w-full px-4 py-2 border border-gray-300 rounded-lg">
289
+ `;
290
+ }
291
+
292
+ examQuestions.appendChild(questionCard);
293
+
294
+ // Update navigation buttons
295
+ const prevBtn = document.getElementById('prev-question');
296
+ const nextBtn = document.getElementById('next-question');
297
+
298
+ prevBtn.classList.toggle('hidden', index === 0);
299
+ nextBtn.textContent = index === state.currentExam.questions.length - 1 ? 'Submit Exam' : 'Next Question';
300
+ }
301
+
302
  // Start timer
303
+ const durationInSeconds = exam.duration * 60;
304
  let remainingTime = durationInSeconds;
305
 
306
  updateTimerDisplay(remainingTime);
index.html CHANGED
@@ -121,11 +121,16 @@
121
  <div id="exam-progress" class="absolute top-0 left-0 h-full bg-indigo-600 rounded-full" style="width: 100%"></div>
122
  </div>
123
  </div>
 
124
 
125
- <div id="exam-questions" class="space-y-6"></div>
126
-
127
- <div class="fixed bottom-4 left-0 right-0 px-4">
128
- <button id="submit-exam" class="w-full bg-indigo-600 text-white py-3 px-4 rounded-lg shadow-md hover:bg-indigo-700">
 
 
 
 
129
  Submit Exam
130
  </button>
131
  </div>
 
121
  <div id="exam-progress" class="absolute top-0 left-0 h-full bg-indigo-600 rounded-full" style="width: 100%"></div>
122
  </div>
123
  </div>
124
+ <div id="exam-questions" class="border-4 border-red-600 rounded-lg p-4 relative min-h-[300px]"></div>
125
 
126
+ <div class="fixed bottom-4 left-0 right-0 px-4 flex justify-between">
127
+ <button id="prev-question" class="bg-gray-200 text-gray-800 py-3 px-6 rounded-lg shadow-md hover:bg-gray-300 hidden">
128
+ Previous
129
+ </button>
130
+ <button id="next-question" class="bg-indigo-600 text-white py-3 px-6 rounded-lg shadow-md hover:bg-indigo-700">
131
+ Next Question
132
+ </button>
133
+ <button id="submit-exam" class="w-full bg-indigo-600 text-white py-3 px-4 rounded-lg shadow-md hover:bg-indigo-700">
134
  Submit Exam
135
  </button>
136
  </div>