// Sample questions array - customize as needed
const questions = [
question: "What is the capital of France?",
options: ["Paris", "London", "Berlin", "Madrid"],
answer: "A"
},
question: "What is 2 + 2?",
options: ["3", "4", "5", "6"],
answer: "B"
},
question: "Which planet is known as the Red Planet?",
options: ["Earth", "Mars", "Jupiter", "Venus"],
answer: "B"
},
question: "What is the largest ocean on Earth?",
options: ["Atlantic", "Indian", "Arctic", "Pacific"],
answer: "D"
},
question: "Who wrote 'To Kill a Mockingbird'?",
options: ["Harper Lee", "J.K. Rowling", "Mark Twain", "Ernest Hemingway"],
answer: "A"
];
let currentQuestionIndex = 0;
let answers = new Array([Link]).fill(null);
let timeLeft = 30 * 60; // 30 minutes in seconds
let timerInterval;
function startTimer() {
timerInterval = setInterval(() => {
timeLeft--;
const minutes = [Link](timeLeft / 60);
const seconds = timeLeft % 60;
[Link]('timer').textContent = `Time Remaining: ${minutes}:$
{[Link]().padStart(2, '0')}`;
if (timeLeft <= 0) {
clearInterval(timerInterval);
submitExam();
}, 1000);
function loadQuestion(index) {
const question = questions[index];
[Link]('question-number').textContent = `Question ${index + 1} of $
{[Link]}`;
[Link]('question-text').textContent = [Link];
const optionsContainer = [Link]('options');
[Link] = '';
[Link]((option, i) => {
const label = [Link]('label');
const input = [Link]('input');
[Link] = 'radio';
[Link] = 'answer';
[Link] = [Link](65 + i); // A, B, C, D
if (answers[index] === [Link]) {
[Link] = true;
[Link](input);
[Link]([Link](` ${[Link](65 + i)}) ${option}`));
[Link](label);
});
updateNavigation();
function updateNavigation() {
[Link]('prev-btn').disabled = currentQuestionIndex === 0;
[Link]('next-btn').[Link] = currentQuestionIndex === [Link] - 1 ?
'none' : 'inline-block';
[Link]('submit-btn').[Link] = currentQuestionIndex === [Link] -
1 ? 'inline-block' : 'none';
}
function saveAnswer() {
const selected = [Link]('input[name="answer"]:checked');
if (selected) {
answers[currentQuestionIndex] = [Link];
function submitExam() {
clearInterval(timerInterval);
let score = 0;
[Link]((answer, index) => {
if (answer === questions[index].answer) {
score++;
});
[Link]('.exam-container').[Link] = 'none';
[Link]('results').[Link] = 'block';
[Link]('score').textContent = `You scored ${score} out of ${[Link]}.`;
[Link]('next-btn').addEventListener('click', () => {
saveAnswer();
if (currentQuestionIndex < [Link] - 1) {
currentQuestionIndex++;
loadQuestion(currentQuestionIndex);
});
[Link]('prev-btn').addEventListener('click', () => {
saveAnswer();
if (currentQuestionIndex > 0) {
currentQuestionIndex--;
loadQuestion(currentQuestionIndex);
});
[Link]('submit-btn').addEventListener('click', () => {
saveAnswer();
submitExam();
});
// Initialize
startTimer();
loadQuestion(currentQuestionIndex);