html Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>India Capitals Quiz</title>
<style>
/* CSS Styles for a modern and futuristic look */
body {
margin: 0;
padding: 0;
background-color: #0C0C0C; /* Dark background */
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
color: #FFFFFF;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
#quiz-container {
background: linear-gradient(135deg, #1a1a1a, #0d0d0d);
padding: 40px;
border-radius: 10px;
box-shadow: 0 0 20px rgba(0, 255, 255, 0.2);
text-align: center;
width: 80%;
max-width: 500px;
opacity: 0;
transform: translateY(-20px);
animation: fadeIn 1s forwards;
}
@keyframes fadeIn {
to {
opacity: 1;
transform: translateY(0);
}
}
h1 {
font-size: 2em;
color: #00FFFF; /* Cyan color */
margin-bottom: 20px;
}
#score {
margin-bottom: 20px;
font-size: 1.1em;
color: #00FF00;
}
#question {
font-size: 1.2em;
margin-bottom: 20px;
}
input[type="text"] {
width: 80%;
padding: 10px;
border: none;
border-bottom: 2px solid #00FFFF;
background: transparent;
color: #FFFFFF;
font-size: 1em;
outline: none;
margin-bottom: 20px;
}
input[type="text"]::placeholder {
color: #AAAAAA;
}
#submit {
background-color: #00FFFF;
border: none;
padding: 10px 20px;
border-radius: 5px;
color: #0C0C0C;
font-size: 1em;
cursor: pointer;
transition: background-color 0.3s;
}
#submit:hover {
background-color: #00CED1;
}
#feedback {
margin-top: 20px;
font-size: 1.1em;
opacity: 0;
transition: opacity 0.5s;
}
/* Responsive design */
@media (max-width: 600px) {
#quiz-container {
padding: 20px;
}
h1 {
font-size: 1.5em;
}
input[type="text"] {
width: 100%;
}
}
</style>
</head>
<body>
<div id="quiz-container">
<h1>India Capitals Quiz</h1>
<div id="score">Score: 0 / 0</div>
<div id="question"></div>
<input type="text" id="answer" placeholder="Type your answer here..." autocomplete="off" />
<button id="submit">Submit</button>
<div id="feedback"></div>
</div>
<script>
// JavaScript code for quiz logic
const data = [
{ state: "Andhra Pradesh", capital: "Amaravati" },
{ state: "Arunachal Pradesh", capital: "Itanagar" },
{ state: "Assam", capital: "Dispur" },
{ state: "Bihar", capital: "Patna" },
{ state: "Chhattisgarh", capital: "Raipur" },
{ state: "Goa", capital: "Panaji" },
{ state: "Gujarat", capital: "Gandhinagar" },
{ state: "Haryana", capital: "Chandigarh" },
{ state: "Himachal Pradesh", capital: "Shimla" },
{ state: "Jharkhand", capital: "Ranchi" },
{ state: "Karnataka", capital: "Bengaluru" },
{ state: "Kerala", capital: "Thiruvananthapuram" },
{ state: "Madhya Pradesh", capital: "Bhopal" },
{ state: "Maharashtra", capital: "Mumbai" },
{ state: "Manipur", capital: "Imphal" },
{ state: "Meghalaya", capital: "Shillong" },
{ state: "Mizoram", capital: "Aizawl" },
{ state: "Nagaland", capital: "Kohima" },
{ state: "Odisha", capital: "Bhubaneswar" },
{ state: "Punjab", capital: "Chandigarh" },
{ state: "Rajasthan", capital: "Jaipur" },
{ state: "Sikkim", capital: "Gangtok" },
{ state: "Tamil Nadu", capital: "Chennai" },
{ state: "Telangana", capital: "Hyderabad" },
{ state: "Tripura", capital: "Agartala" },
{ state: "Uttar Pradesh", capital: "Lucknow" },
{ state: "Uttarakhand", capital: "Dehradun" },
{ state: "West Bengal", capital: "Kolkata" }
];
let currentQuestion;
let questionType;
let score = 0;
let totalQuestions = 0;
function generateQuestion() {
const randomIndex = Math.floor(Math.random() * data.length);
const item = data[randomIndex];
// Randomly choose the question type
questionType = Math.random() < 0.5 ? 'capital-to-state' : 'state-to-capital';
let questionText;
if (questionType === 'capital-to-state') {
// Given the capital, ask for the state
questionText = `Which state has "<span style="color:#00FFFF;">${item.capital}</span>" as its capital?`;
currentQuestion = { correctAnswer: item.state.toLowerCase() };
} else {
// Given the state, ask for the capital
questionText = `What is the capital city of "<span style="color:#00FFFF;">${item.state}</span>"?`;
currentQuestion = { correctAnswer: item.capital.toLowerCase() };
}
document.getElementById('question').innerHTML = questionText;
document.getElementById('answer').value = '';
document.getElementById('feedback').innerText = '';
document.getElementById('feedback').style.opacity = '0';
}
document.getElementById('submit').addEventListener('click', function() {
const userAnswer = document.getElementById('answer').value.trim().toLowerCase();
if (userAnswer === '') {
alert('Please enter your answer.');
return;
}
totalQuestions++;
if (userAnswer === currentQuestion.correctAnswer) {
score++;
document.getElementById('feedback').innerHTML = '<span style="color: #32CD32;">Correct!</span>';
} else {
document.getElementById('feedback').innerHTML = `<span style="color: #FF6347;">Incorrect!</span> The correct answer is "<span style="color:#00FFFF;">${currentQuestion.correctAnswer.charAt(0).toUpperCase() + currentQuestion.correctAnswer.slice(1)}</span>".`;
}
document.getElementById('score').innerText = `Score: ${score} / ${totalQuestions}`;
document.getElementById('feedback').style.opacity = '1';
setTimeout(generateQuestion, 2000); // After 2 seconds, generate a new question
});
// Initialize the first question
generateQuestion();
</script>
</body>
</html>