create a quiz form that contains 10000 mcqs from all the topics of C language. the exam consists of 30 random questions taken from those 10000 questions. there will be a timer which closes exam automatically after 1 hour. generate the above form. i will add additional queries later.
1 Answer
1Hi rajan_rajan!
Building a quiz system is a fantastic project!
Because a single message cannot hold 10,000 questions, the best approach is to store your question bank in an external JSON file (or database) and use JavaScript to pick 30 questions at random and manage the 1-hour timer.
Here is a lightweight, working template to get you started:
<!DOCTYPE html>
<html>
<head><title>C Language Quiz</title></head>
<body>
<h2>Time Left: <span id="timer">60:00</span></h2>
<form id="quizForm">
<div id="quizContainer"></div>
<button type="submit">Submit Exam</button>
</form>
<script>
// 1. 60-Minute Countdown Timer
let timeLeft = 60 * 60;
const timerEl = document.getElementById("timer");
const countdown = setInterval(() => {
timeLeft--;
let mins = Math.floor(timeLeft / 60);
let secs = timeLeft % 60;
timerEl.textContent = `${mins}:${secs < 10 ? '0' : ''}${secs}`;
if (timeLeft <= 0) {
clearInterval(countdown);
alert("Time is up! Exam auto-submitting.");
document.getElementById("quizForm").requestSubmit();
}
}, 1000);
// 2. Load questions.json & Pick 30 Randomly
fetch('questions.json')
.then(res => res.json())
.then(allQuestions => {
const selected = allQuestions.sort(() => 0.5 - Math.random()).slice(0, 30);
const container = document.getElementById("quizContainer");
selected.forEach((q, i) => {
container.innerHTML += `<p><b>${i + 1}. ${q.question}</b></p>` +
q.options.map(opt => `<label><input type="radio" name="q${i}" value="${opt}"> ${opt}</label><br>`).join('');
});
});
</script>
</body>
</html>
Would you like me to write a starter batch of C language MCQs in the exact JSON format needed for this? Just press Reply! ![]()