Professional Documents
Culture Documents
Quiz Game
Quiz Game
DOCTYPE html>
<html>
<head>
<title>Quiz Game</title>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
}
h1 {
color: #333;
}
#quiz-container {
margin-top: 20px;
}
#question-container {
margin-bottom: 10px;
}
#answers-container {
display: flex;
flex-wrap: wrap;
justify-content: center;
gap: 10px;
margin-bottom: 10px;
}
.answer-btn {
padding: 10px 20px;
font-size: 16px;
}
#result {
font-size: 18px;
margin-bottom: 10px;
}
#timer {
font-size: 16px;
}
</style>
<body>
<h1>Quiz Game</h1>
<div id="quiz-container">
<div id="question-container">
<p id="question"></p>
</div>
<div id="answers-container">
<button class="answer-btn"></button>
<button class="answer-btn"></button>
<button class="answer-btn"></button>
<button class="answer-btn"></button>
</div>
<div id="result"></div>
<div id="timer">Time: <span id="time"></span></div>
</div>
<script>
// Quiz questions and answers
const quizData = [
{
question: "What is the capital of France?",
answers: ["Paris", "London", "Rome", "Madrid"],
correctAnswer: "Paris"
},
{
question: "Who painted the Mona Lisa?",
answers: ["Leonardo da Vinci", "Pablo Picasso", "Vincent van Gogh",
"Michelangelo"],
correctAnswer: "Leonardo da Vinci"
},
{
question: "What is the tallest mountain in the world?",
answers: ["Mount Everest", "K2", "Kangchenjunga", "Makalu"],
correctAnswer: "Mount Everest"
}
];
let currentQuestionIndex = 0;
let score = 0;
let timer;
startTimer();
showQuestion();
}
answersContainer.innerHTML = '';
question.answers.forEach(answer => {
const answerButton = document.createElement('button');
answerButton.classList.add('answer-btn');
answerButton.innerText = answer;
answerButton.addEventListener('click', () => {
checkAnswer(answer);
});
answersContainer.appendChild(answerButton);
});
} else {
endQuiz();
}
}
currentQuestionIndex++;
showQuestion();
}
function updateTime() {
time++;
timeElement.innerText = formatTime(time);
timer = setTimeout(updateTime, 1000);
}
updateTime();
}
</script>
</body>
</html>