Memory Game
Memory Game
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Memory Quiz Game</title>
<style>
body {
margin: 0;
font-family: Arial, sans-serif;
color: white;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
text-align: center;
background-size: cover;
background-position: center;
transition: background 0.5s;
}
.quiz-container {
background: rgba(0, 0, 0, 0.7);
padding: 20px;
border-radius: 10px;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
max-width: 600px;
width: 90%;
}
.level {
font-size: 1.5rem;
margin-bottom: 10px;
}
.question {
font-size: 1.5rem;
margin-bottom: 20px;
}
.options {
display: flex;
flex-direction: column;
gap: 10px;
}
.option {
background: #1abc9c;
border: none;
border-radius: 5px;
padding: 10px;
color: white;
font-size: 1rem;
cursor: pointer;
transition: background 0.3s;
}
.option:hover {
background: #16a085;
}
.result {
margin-top: 20px;
font-size: 1.2rem;
font-weight: bold;
}
.timer {
font-size: 1.2rem;
margin-top: 10px;
}
</style>
</head>
<body>
<div class="quiz-container">
<div class="level" id="level">Level 1</div>
<div class="question" id="question">Loading question...</div>
<div class="options" id="options"></div>
<div class="timer" id="timer"></div>
<div class="result" id="result"></div>
</div>
<script>
const maxLevels = 100;
let currentLevel = 1;
let currentQuestionIndex = 0;
let score = 0;
let timer;
let timeLeft = 60;
function loadQuestion() {
clearInterval(timer);
timeLeft = 60;
timerElement.textContent = `Time left: ${timeLeft}s`;
timer = setInterval(() => {
timeLeft--;
timerElement.textContent = `Time left: ${timeLeft}s`;
if (timeLeft === 0) {
clearInterval(timer);
restartLevel();
}
}, 1000);
currentQuestion.options.forEach(option => {
const button = document.createElement("button");
button.classList.add("option");
button.textContent = option;
button.onclick = () => checkAnswer(option);
optionsElement.appendChild(button);
});
}
function checkAnswer(selectedOption) {
clearInterval(timer);
const currentQuestion = quizData[currentLevel - 1][currentQuestionIndex];
setTimeout(() => {
showLevelCompletion();
}, 1000);
} else {
setTimeout(() => {
resultElement.textContent = "";
loadQuestion();
}, 1500);
}
} else {
resultElement.textContent = `Wrong! The correct answer was: $
{currentQuestion.answer}`;
resultElement.style.color = "#e74c3c";
setTimeout(restartLevel, 3000);
}
}
function restartLevel() {
resultElement.textContent = "Restarting level...";
resultElement.style.color = "#f1c40f";
currentQuestionIndex = 0;
setTimeout(() => {
resultElement.textContent = "";
loadQuestion();
}, 3000);
}
function loadQuestion() {
clearInterval(timer);
timeLeft = 60;
timerElement.textContent = `Time left: ${timeLeft}s`;
timer = setInterval(() => {
timeLeft--;
timerElement.textContent = `Time left: ${timeLeft}s`;
if (timeLeft === 0) {
clearInterval(timer);
restartLevel();
}
}, 1000);
shuffledOptions.forEach(option => {
const button = document.createElement("button");
button.classList.add("option");
button.textContent = option;
button.onclick = () => checkAnswer(option);
optionsElement.appendChild(button);
});
}
function showLevelCompletion() {
document.body.style.background = generateBackground(currentLevel);
questionElement.textContent = bonusQuestion.question;
bonusQuestion.options.forEach(option => {
const button = document.createElement("button");
button.classList.add("option");
button.textContent = option;
button.onclick = () => {
if (option === bonusQuestion.answer) {
resultElement.textContent = "Correct! Moving to the next level.";
resultElement.style.color = "#2ecc71";
} else {
resultElement.textContent = "Wrong! But don't worry, you'll continue to
the next level.";
resultElement.style.color = "#e74c3c";
}
setTimeout(() => {
levelElement.textContent = `Level ${currentLevel}`;
resultElement.textContent = "";
loadQuestion();
}, 3000);
};
optionsElement.appendChild(button);
});
}
function showFinalScore() {
questionElement.textContent = "Congratulations! You've completed the quiz.";
optionsElement.innerHTML = "";
resultElement.textContent = `Your final score is: ${score}`;
resultElement.style.color = "#3498db";
}
document.body.style.background = generateBackground(currentLevel);
loadQuestion();
</script>
</body>
</html>