Mcq v1.7.1
Muhammad Mahabubul Alam
Bangla Model Test!
Time Left: 00:00
`;
const intermediateAdBannerCode = `
Your 300x250 Box Ad Here
Replace this with your ad script.
`;
const bottomAdBannerCode = `
Your 300x250 Box Ad Here
Replace this with your ad script.
`;
// --- END OF CUSTOMIZATION AREA ---
// (Do not edit below this line)
const quizForm = document.getElementById('quiz-form');
const submitBtn = document.getElementById('submit-btn');
const resultsContainer = document.getElementById('results-container');
const timerDisplay = document.getElementById('timer-display');
const postSubmitContainer = document.getElementById('post-submit-container');
let timeLeft = quizDurationMinutes * 60;
let timerInterval;
let submitted = false;
let finalScore, finalFullMarks, finalCorrect, finalWrong, finalSkipped;
function buildQuiz() {
let output = '';
quizData.forEach((currentQuestion, questionNumber) => {
const options = [];
const optionLetters = ['a', 'b', 'c', 'd'];
for (let i = 0; i < currentQuestion.options.length; i++) {
options.push(
`
`
);
}
output += `
${questionNumber + 1}. ${currentQuestion.question}
${options.join('')}
`;
if (questionNumber === 2 || questionNumber === 5) {
output += smallBannerAdCode;
}
});
quizForm.innerHTML = output;
}
function addSelectionHighlighting() {
quizForm.querySelectorAll('input[type="radio"]').forEach(radio => {
radio.addEventListener('change', (event) => {
const questionName = event.target.name;
quizForm.querySelectorAll(`input[name="${questionName}"]`).forEach(r => {
r.parentElement.classList.remove('selected');
});
event.target.parentElement.classList.add('selected');
});
});
}
function submitQuiz() {
if (submitted) return;
submitted = true;
clearInterval(timerInterval);
let score = 0, correctCount = 0, wrongCount = 0;
const totalQuestions = quizData.length;
const fullMarks = totalQuestions;
quizData.forEach((currentQuestion, questionNumber) => {
const selector = `input[name=question${questionNumber}]:checked`;
const userAnswerNode = quizForm.querySelector(selector);
if (userAnswerNode) {
if (userAnswerNode.value === currentQuestion.answer) { score += 1; correctCount++; }
else { score -= 0.5; wrongCount++; }
}
});
finalScore = score;
finalFullMarks = fullMarks;
finalCorrect = correctCount;
finalWrong = wrongCount;
finalSkipped = totalQuestions - correctCount - wrongCount;
lockForm();
quizForm.style.display = 'none';
submitBtn.style.display = 'none';
timerDisplay.style.display = 'none';
// NEW: The intermediate screen now includes an ad box
postSubmitContainer.innerHTML = `
Thank you for taking the test!
To see your score and the detailed answer sheet, please click the button below.
${intermediateAdBannerCode}
`;
postSubmitContainer.style.display = 'block';
// NEW: Auto-scroll to the "Thank You" message
postSubmitContainer.scrollIntoView({ behavior: 'smooth' });
}
function showFinalResults() {
postSubmitContainer.style.display = 'none';
displayResults(finalScore, finalFullMarks, finalCorrect, finalWrong, finalSkipped);
}
function displayResults(score, fullMarks, correct, wrong, skipped) {
let questionReviewHTML = '';
quizData.forEach((currentQuestion, questionNumber) => {
const userAnswerNode = quizForm.querySelector(`input[name=question${questionNumber}]:checked`);
const userAnswer = userAnswerNode ? userAnswerNode.value : null;
let optionsHTML = '';
const optionLetters = ['a', 'b', 'c', 'd'];
currentQuestion.options.forEach((option, index) => {
const letter = optionLetters[index];
let className = 'option';
if (letter === currentQuestion.answer) className += ' correct';
else if (letter === userAnswer) className += ' wrong';
optionsHTML += `
${letter.toUpperCase()}) ${option}
`;
});
questionReviewHTML += `
${questionNumber + 1}. ${currentQuestion.question}
${optionsHTML}
Explanation: ${currentQuestion.explanation}
`;
// NEW: Add ads to the results list
if (questionNumber === 2 || questionNumber === 5) {
questionReviewHTML += smallBannerAdCode;
}
});
resultsContainer.innerHTML = `
Score Breakdown
✅ Correct: ${correct} × 1 = ${correct} marks
❌ Wrong: ${wrong} × -0.5 = ${wrong * -0.5} marks
⏭️ Skipped: ${skipped} × 0 = ${skipped * 0} marks
Total Score: ${score} out of ${fullMarks}
Below are the correct answers and explanations for your review.
${bottomAdBannerCode}
${questionReviewHTML}`;
resultsContainer.style.display = 'block';
new Chart(document.getElementById('resultsPieChart'), {
type: 'pie',
data: {
labels: ['Correct', 'Wrong', 'Skipped'],
datasets: [{ data: [correct, wrong, skipped], backgroundColor: ['#28a745', '#dc3545', '#ffc107'], hoverOffset: 4 }]
},
options: { responsive: true, plugins: { legend: { position: 'top' }, title: { display: true, text: 'Your Performance' } } }
});
resultsContainer.scrollIntoView({ behavior: 'smooth' });
}
function lockForm() {
quizForm.querySelectorAll('input[type="radio"]').forEach(input => { input.disabled = true; });
submitBtn.disabled = true;
submitBtn.textContent = 'Test Submitted';
}
function startTimer() {
timerInterval = setInterval(() => {
if (timeLeft <= 0) {
clearInterval(timerInterval);
timerDisplay.innerHTML = "Time's Up!";
submitQuiz();
return;
}
timeLeft--;
const minutes = Math.floor(timeLeft / 60);
let seconds = timeLeft % 60;
seconds = seconds < 10 ? '0' + seconds : seconds;
timerDisplay.innerHTML = `Time Left: ${minutes}:${seconds}`;
}, 1000);
}
window.onload = function() {
buildQuiz();
addSelectionHighlighting();
startTimer();
};