Mock Tests
:root {
–bg-deep: #F0F4F8; –bg-panel: #FFFFFF; –bg-input: #F8FAFC;
–border-main: #E2E8F0; –text-main: #1A202C; –text-muted: #718096;
–accent-teal: #0284C7; –accent-sage: #10B981; –accent-coral: #DC2626;
–btn-text: #FFF;
}
body { font-family: ‘Segoe UI’, sans-serif; background-color: var(–bg-deep); color: var(–text-main); margin: 0; padding: 0; }
#setup-screen, #quiz-screen, #result-screen { max-width: 900px; margin: 40px auto; background: var(–bg-panel); padding: 30px; border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,0.1); border: 1px solid var(–border-main); }
#quiz-screen, #result-screen { display: none; }
input[type=”text”] { width: 100%; padding: 12px; margin: 10px 0 20px 0; border: 1px solid var(–border-main); border-radius: 6px; font-size: 16px; box-sizing: border-box; }
button.btn-primary { background: var(–accent-teal); color: var(–btn-text); font-weight: bold; padding: 15px 30px; border: none; border-radius: 6px; cursor: pointer; font-size: 18px; width: 100%; transition: 0.3s; }
button.btn-primary:hover { opacity: 0.9; transform: translateY(-2px); }
#top-bar { display: flex; justify-content: space-between; align-items: center; padding-bottom: 15px; border-bottom: 2px solid var(–border-main); margin-bottom: 25px; }
#timer-display { font-size: 24px; font-weight: bold; color: var(–accent-coral); background: #fee2e2; padding: 5px 15px; border-radius: 8px; }
#question-box { font-size: 24px; font-weight: bold; margin-bottom: 20px; line-height: 1.5; }
.options-grid { display: flex; flex-direction: column; gap: 10px; margin-bottom: 30px; }
.option { background: var(–bg-input); padding: 15px 20px; border-radius: 8px; font-size: 18px; border: 2px solid var(–border-main); cursor: pointer; transition: 0.2s; }
.option:hover { border-color: var(–accent-teal); }
.option.selected { background: #e0f2fe; border-color: var(–accent-teal); font-weight: bold; }
.nav-buttons { display: flex; justify-content: space-between; gap: 15px; }
.nav-buttons button { flex: 1; padding: 12px; font-size: 16px; font-weight: bold; border-radius: 6px; cursor: pointer; border: none; }
.btn-prev { background: var(–border-main); color: var(–text-main); }
.btn-next { background: var(–accent-teal); color: white; }
.btn-submit { background: var(–accent-coral); color: white; margin-top: 20px; width: 100%; padding: 15px; font-size: 18px; font-weight:bold; border:none; border-radius: 6px; cursor: pointer;}
/* Grid */
#mcq-grid { display: grid; grid-template-columns: repeat(10, 1fr); gap: 10px; margin-top: 30px; padding-top: 20px; border-top: 2px solid var(–border-main); }
.grid-item { background: var(–bg-input); font-size: 14px; font-weight: bold; border: 1px solid var(–border-main); padding: 10px; border-radius: 6px; cursor: pointer; text-align: center; }
.grid-item.answered { background: var(–accent-teal); color: white; border-color: var(–accent-teal); }
.grid-item.current { outline: 3px solid var(–accent-coral); }
#result-screen { text-align: center; }
.score-circle { width: 150px; height: 150px; border-radius: 50%; background: var(–accent-teal); color: white; display: flex; align-items: center; justify-content: center; font-size: 40px; font-weight: bold; margin: 0 auto 20px auto; border: 8px solid #bae6fd; }
MathJax = { tex: { inlineMath: [[‘$’, ‘$’], [‘\\(‘, ‘\\)’]], displayMath: [[‘$$’, ‘$$’], [‘\\[‘, ‘\\]’]] }, svg: { fontCache: ‘global’ } };
📝 Mock Test Portal
Enter your name to begin the exam.
let questions = [];
let studentAnswers = [];
let currentIndex = 0;
let timer;
let timeLeft = 0;
function startExam() {
const nameInput = document.getElementById(‘studentName’).value;
const startBtn = document.getElementById(‘startBtn’);
// 🚨 IMPORTANT: SET EXAM TIME AND FILE URL HERE 🚨
const examDurationMinutes = 60; // Set your total exam time in minutes here
const testFileURL = “https://prabhclasses.com/wp-content/uploads/2026/10/Punjab-GK-Mock-Test-1.txt”;
if (!nameInput) return alert(“Please enter your name.”);
document.getElementById(‘student-display’).innerText = “Candidate: ” + nameInput;
document.getElementById(‘result-student-name’).innerText = “Candidate: ” + nameInput;
timeLeft = examDurationMinutes * 60;
// Show loading state
startBtn.innerText = “Loading Test… ⏳”;
startBtn.disabled = true;
// Fetch the file automatically from your server
fetch(testFileURL)
.then(response => {
if (!response.ok) throw new Error(“Could not find the test file. Check the URL!”);
return response.text();
})
.then(textData => {
questions = parseMCQs(textData);
if(questions.length === 0) {
alert(“No valid MCQs found in file.”);
startBtn.innerText = “Start Exam 🚀”;
startBtn.disabled = false;
return;
}
studentAnswers = new Array(questions.length).fill(null);
document.getElementById(‘setup-screen’).style.display = ‘none’;
document.getElementById(‘quiz-screen’).style.display = ‘block’;
startTimer();
buildGrid();
loadQuestion(0);
})
.catch(error => {
alert(“Error: ” + error.message);
startBtn.innerText = “Start Exam 🚀”;
startBtn.disabled = false;
});
}
function parseMCQs(rawData) {
const parsed = [];
const questionBlocks = rawData.split(/(?=Q:)/i).filter(b => b.trim().length > 0);
questionBlocks.forEach(block => {
let qText = “”, opts = {}, correct = “”;
let expMatch = block.match(/Exp:\s*([\s\S]+?)$/i);
if (expMatch) block = block.replace(/Exp:\s*([\s\S]+?)$/i, ”);
let ansMatch = block.match(/Ans:\s*([A-D])/i);
if (ansMatch) { correct = ansMatch[1].toUpperCase(); block = block.replace(/Ans:\s*([A-D])/i, ”); }
block.split(‘\n’).filter(l => l.trim() !== ”).forEach(line => {
if(line.match(/^[A-D]\)/i)) opts[line.charAt(0).toUpperCase()] = line.trim();
else qText += (line.toUpperCase().startsWith(“Q:”) ? line.substring(2).trim() : line.trim()) + “
“;
});
if(correct) parsed.push({ question: qText, options: opts, correct: correct });
});
return parsed;
}
function startTimer() {
timer = setInterval(() => {
timeLeft–;
let m = Math.floor(timeLeft / 60);
let s = timeLeft % 60;
document.getElementById(‘timer-display’).innerText = `${m < 10 ? '0':''}${m}:${s < 10 ? '0':''}${s}`;
if (timeLeft {
const el = document.getElementById(‘opt’ + letter);
el.innerHTML = q.options[letter] || letter + “) “;
el.classList.remove(‘selected’);
if (studentAnswers[currentIndex] === letter) el.classList.add(‘selected’);
});
updateGridUI();
// Render MathJax if there are math equations
if (window.MathJax) {
MathJax.typesetPromise().catch((err) => console.log(‘MathJax error: ‘, err.message));
}
}
function selectOption(letter) {
studentAnswers[currentIndex] = letter;
[‘A’,’B’,’C’,’D’].forEach(l => document.getElementById(‘opt’ + l).classList.remove(‘selected’));
document.getElementById(‘opt’ + letter).classList.add(‘selected’);
updateGridUI();
}
function nextQuestion() { if(currentIndex 0) loadQuestion(currentIndex – 1); }
function buildGrid() {
const box = document.getElementById(‘mcq-grid’); box.innerHTML = ”;
questions.forEach((q, i) => {
const btn = document.createElement(‘div’);
btn.className = ‘grid-item’;
btn.id = ‘grid-btn-‘ + i;
btn.innerText = i + 1;
btn.onclick = () => loadQuestion(i);
box.appendChild(btn);
});
}
function updateGridUI() {
questions.forEach((q, i) => {
const btn = document.getElementById(‘grid-btn-‘ + i);
btn.classList.remove(‘current’, ‘answered’);
if(studentAnswers[i] !== null) btn.classList.add(‘answered’);
if(i === currentIndex) btn.classList.add(‘current’);
});
}
function submitExam() {
if(timeLeft > 0) {
let unanswered = studentAnswers.filter(a => a === null).length;
if (unanswered > 0) {
if(!confirm(`You have ${unanswered} unanswered questions. Are you sure you want to submit?`)) return;
} else {
if(!confirm(“Are you sure you want to submit your exam?”)) return;
}
}
clearInterval(timer);
let score = 0;
questions.forEach((q, i) => { if(studentAnswers[i] === q.correct) score++; });
document.getElementById(‘quiz-screen’).style.display = ‘none’;
document.getElementById(‘result-screen’).style.display = ‘block’;
document.getElementById(‘final-score-display’).innerText = `${score}/${questions.length}`;
document.getElementById(‘correct-count’).innerText = score;
document.getElementById(‘incorrect-count’).innerText = questions.length – score;
}
Showing the single result
