function showQuestion() {
if (current >= questions.length) {
let score = correctAnswers + " / " + questions.length;
document.getElementById("quiz").innerHTML = `
`;
document.getElementById("quiz").innerHTML = html;
}
let correctAnswers = 0;
function checkAnswer(selected) {
const q = questions[current];
const resultDiv = document.getElementById(`result${current}`);
const options = document.querySelectorAll(".option");
options.forEach((opt, i) => {
opt.onclick = null;
if (i === q.c) opt.classList.add("correct");
else if (i === selected) opt.classList.add("wrong");
});
if (selected === q.c) {
resultDiv.innerHTML = "إجابة صحيحة";
correctAnswers++;
} else {
resultDiv.innerHTML = `خطأ، الإجابة الصحيحة: ${q.a[q.c]}`;
}
setTimeout(() => {
current++;
showQuestion();
}, 2000);
}
function restartQuiz() {
current = 0;
correctAnswers = 0;
showQuestion();
}
انتهى الامتحان، أحسنت!
درجتك: ${score}
`; return; } const q = questions[current]; let html = `س${current + 1}: ${q.q}
`; q.a.forEach((opt, i) => { html += `${opt}
`;
});
html += `