Loading...

🧠 Mini Quiz Game by marketing2advertising

Advertisements

 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();

  • Related Posts

    🚘 Car Dodging Game by marketing2advertising

     Game by marketing2advertising 🚘 Car Dodging Game on the 🛣️ Use the arrow keys to dodge the red cars and survive as long as you can! Score: 0 const canvas…

    🧩 Memory Matching Game by marketing2advertising

     Game by marketing2advertising 🧩 Memory Matching Game Click any two cards to find matching pairs const emojis = [‘🍎’,’🍌’,’🍇’,’🍓’,’🍒’,’🍍’]; let cards = […emojis, …emojis]; // Duplicate for matching cards =…

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    You Missed

    VJ Junior – Yakuza Princess

    VJ Junior – Yakuza Princess

    VJ Junior – Conan the Barbarian

    VJ Junior – Conan the Barbarian

    VJ Junior – After burn

    VJ Junior – After burn

    VJ Junior – Chronicles of narnia

    VJ Junior – Chronicles of narnia

    Vj Junior – Day Shift

    Vj Junior – Day Shift

    Vj Junior – Red Ghost

    Vj Junior – Red Ghost
    ▲ Ad