
Game by marketing2advertising
🧠 Mini Quiz Game
const quizData = [
{
question: “What is the capital of France?”,
options: [“Berlin”, “Madrid”, “Paris”, “London”],
answer: “Paris”
},
{
question: “Which planet is known as the Red Planet?”,
options: [“Earth”, “Venus”, “Mars”, “Jupiter”],
answer: “Mars”
},
{
question: “Which animal is known as the king of the jungle?”,
options: [“Tiger”, “Elephant”, “Lion”, “Giraffe”],
answer: “Lion”
}
];
let currentQuestion = 0;
let score = 0;
const questionEl = document.getElementById(“question”);
const answersEl = document.getElementById(“answers”);
const scoreEl = document.getElementById(“score”);
const nextBtn = document.getElementById(“next-btn”);
function loadQuestion() {
const q = quizData[currentQuestion];
questionEl.textContent = q.question;
answersEl.innerHTML = “”;
nextBtn.style.display = “none”;
q.options.forEach(option => {
const btn = document.createElement(“button”);
btn.textContent = option;
btn.style.display = “block”;
btn.style.margin = “10px 0”;
btn.style.padding = “10px”;
btn.onclick = () => checkAnswer(option);
answersEl.appendChild(btn);
});
}
function checkAnswer(selected) {
const correct = quizData[currentQuestion].answer;
if (selected === correct) {
score++;
scoreEl.textContent = “✅ Correct!”;
} else {
scoreEl.textContent = `❌ Wrong. The correct answer was “${correct}”.`;
}
Array.from(answersEl.children).forEach(btn => btn.disabled = true);
nextBtn.style.display = “inline-block”;
}
function nextQuestion() {
currentQuestion++;
scoreEl.textContent = “”;
if (currentQuestion < quizData.length) {
loadQuestion();
} else {
questionEl.textContent = "🎉 Quiz Finished!";
answersEl.innerHTML = "";
scoreEl.textContent = `Your Score: ${score}/${quizData.length}`;
nextBtn.style.display = "none";
}
}
// Start the quiz
loadQuestion();