Changed around line 1
+ document.addEventListener('DOMContentLoaded', () => {
+ const loginForm = document.getElementById('login-form');
+ const examContainer = document.getElementById('exam-container');
+ const loginContainer = document.getElementById('login-container');
+ const timeDisplay = document.getElementById('time');
+ const prevBtn = document.getElementById('prev-btn');
+ const nextBtn = document.getElementById('next-btn');
+ const submitBtn = document.getElementById('submit-btn');
+
+ let currentQuestion = 0;
+ let timeRemaining = 3600; // 60 minutes
+ let timer;
+
+ // Sample exam data
+ const examData = {
+ questions: [
+ {
+ question: "What is the capital of France?",
+ options: ["London", "Berlin", "Paris", "Madrid"],
+ correct: 2
+ },
+ // Add more questions here
+ ]
+ };
+
+ loginForm.addEventListener('submit', (e) => {
+ e.preventDefault();
+ startExam();
+ });
+
+ function startExam() {
+ loginContainer.classList.add('hidden');
+ examContainer.classList.remove('hidden');
+ loadQuestion(0);
+ startTimer();
+ }
+
+ function loadQuestion(index) {
+ const question = examData.questions[index];
+ document.getElementById('question-text').textContent = question.question;
+
+ const optionsContainer = document.getElementById('options-container');
+ optionsContainer.innerHTML = '';
+
+ question.options.forEach((option, i) => {
+ const button = document.createElement('button');
+ button.textContent = option;
+ button.classList.add('option-btn');
+ button.addEventListener('click', () => selectOption(i));
+ optionsContainer.appendChild(button);
+ });
+
+ updateNavigation();
+ }
+
+ function selectOption(index) {
+ const options = document.querySelectorAll('.option-btn');
+ options.forEach(opt => opt.classList.remove('selected'));
+ options[index].classList.add('selected');
+ }
+
+ function updateNavigation() {
+ prevBtn.disabled = currentQuestion === 0;
+ nextBtn.textContent = currentQuestion === examData.questions.length - 1 ? "Review" : "Next";
+ submitBtn.classList.toggle('hidden', currentQuestion !== examData.questions.length - 1);
+ }
+
+ function startTimer() {
+ timer = setInterval(() => {
+ timeRemaining--;
+ const minutes = Math.floor(timeRemaining / 60);
+ const seconds = timeRemaining % 60;
+ timeDisplay.textContent = `${String(minutes).padStart(2, '0')}:${String(seconds).padStart(2, '0')}`;
+
+ if (timeRemaining <= 0) {
+ clearInterval(timer);
+ submitExam();
+ }
+ }, 1000);
+ }
+
+ prevBtn.addEventListener('click', () => {
+ if (currentQuestion > 0) {
+ currentQuestion--;
+ loadQuestion(currentQuestion);
+ }
+ });
+
+ nextBtn.addEventListener('click', () => {
+ if (currentQuestion < examData.questions.length - 1) {
+ currentQuestion++;
+ loadQuestion(currentQuestion);
+ }
+ });
+
+ submitBtn.addEventListener('click', submitExam);
+
+ function submitExam() {
+ clearInterval(timer);
+ // Add submission logic here
+ alert('Exam submitted successfully!');
+ }
+ });