Quiz code
Quiz code
DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Dynamic Quiz</title>
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: linear-gradient(to right, #74ebd5, #ACB6E5);
margin: 0;
padding: 0;
}
.container {
max-width: 700px;
background: #fff;
margin: 50px auto;
padding: 30px;
border-radius: 10px;
box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}
.question {
font-size: 22px;
margin-bottom: 20px;
}
.options label {
display: block;
margin: 10px 0;
font-size: 18px;
cursor: pointer;
padding: 8px;
border: 1px solid #ddd;
border-radius: 5px;
transition: background 0.3s, border 0.3s;
}
.options label:hover {
background: #f0f0f0;
border-color: #ccc;
}
button {
padding: 12px 25px;
font-size: 18px;
border: none;
border-radius: 5px;
background: #4CAF50;
color: #fff;
cursor: pointer;
transition: background 0.3s;
margin-top: 20px;
}
button:hover {
background: #45a049;
}
.result {
font-size: 24px;
font-weight: bold;
margin-bottom: 20px;
}
.feedback div {
margin-bottom: 20px;
padding: 15px;
border: 1px solid #ddd;
border-radius: 5px;
background: #f9f9f9;
}
.correct {
color: green;
font-weight: bold;
}
.wrong {
color: red;
font-weight: bold;
}
</style>
</head>
<body>
<div class="container">
<div id="quiz"></div>
</div>
<script>
// Define a pool of questions (General Knowledge and Asia-related)
const allQuestions = [
{
question: "What is the capital of Japan?",
options: ["Tokyo", "Osaka", "Kyoto", "Hiroshima"],
answer: 0
},
{
question: "Which is the largest continent in the world?",
options: ["Asia", "Africa", "Europe", "Antarctica"],
answer: 0
},
{
question: "What is the longest river in Asia?",
options: ["Yangtze", "Ganges", "Mekong", "Yellow River"],
answer: 0
},
{
question: "Who wrote the play 'Hamlet'?",
options: ["William Shakespeare", "Charles Dickens", "Mark Twain", "Jane Austen"],
answer: 0
},
{
question: "Which is the largest country in Asia by land area?",
options: ["China", "India", "Russia", "Mongolia"],
answer: 2
},
{
question: "What is the official language of Brazil?",
options: ["Spanish", "Portuguese", "English", "French"],
answer: 1
},
{
question: "Which Asian country is famous for the Great Wall?",
options: ["India", "China", "Japan", "South Korea"],
answer: 1
},
{
question: "What is the smallest country in the world?",
options: ["Monaco", "Vatican City", "Nauru", "San Marino"],
answer: 1
},
{
question: "Which element has the chemical symbol 'O'?",
options: ["Gold", "Oxygen", "Osmium", "Iron"],
answer: 1
},
{
question: "Who is known as the father of computers?",
options: ["Albert Einstein", "Charles Babbage", "Isaac Newton", "Alan Turing"],
answer: 1
},
{
question: "What is the largest desert in Asia?",
options: ["Gobi Desert", "Arabian Desert", "Kalahari Desert", "Sahara Desert"],
answer: 0
},
{
question: "Which country hosted the 2018 FIFA World Cup?",
options: ["Russia", "Qatar", "Brazil", "Germany"],
answer: 0
},
{
question: "Which Asian country is known for sushi?",
options: ["China", "South Korea", "Japan", "Vietnam"],
answer: 2
},
{
question: "What is the tallest mountain in the world?",
options: ["K2", "Kangchenjunga", "Mount Everest", "Lhotse"],
answer: 2
},
{
question: "Who painted the Mona Lisa?",
options: ["Pablo Picasso", "Leonardo da Vinci", "Vincent van Gogh", "Claude
Monet"],
answer: 1
}
];
// Display results, including score, pass/fail status, and feedback for each question
function showResult() {
const quizDiv = document.getElementById('quiz');
quizDiv.innerHTML = "";