Spaces:
Build error
Build error
File size: 18,411 Bytes
736a2a0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dynamic Quiz Website</title>
<style>
/* Basic styling */
body {
font-family: Arial, sans-serif;
background-color: #f4f4f9;
color: #333;
text-align: center;
padding: 20px;
}
h1 {
font-size: 32px;
margin-bottom: 20px;
color: #007BFF;
}
.menu, .quiz, .score, .leaderboard {
max-width: 600px;
margin: 0 auto;
padding: 20px;
background-color: #fff;
border-radius: 10px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}
button {
padding: 10px 20px;
background-color: #007BFF;
color: #fff;
border: none;
border-radius: 5px;
font-size: 16px;
cursor: pointer;
transition: background-color 0.3s ease;
margin: 5px;
}
button:hover {
background-color: #0056b3;
}
.question {
margin-bottom: 20px;
}
.options {
display: flex;
flex-direction: column;
align-items: center;
}
.options button {
width: 80%;
margin: 5px 0;
}
.score {
font-size: 24px;
margin-top: 20px;
}
.progress-bar {
width: 100%;
height: 10px;
background-color: #e0e0e0;
border-radius: 5px;
margin-bottom: 20px;
}
.progress {
height: 100%;
background-color: #007BFF;
border-radius: 5px;
}
.timer {
font-size: 20px;
margin-bottom: 20px;
}
.hint {
color: #ff5722;
cursor: pointer;
margin-top: 10px;
}
.leaderboard {
margin-top: 20px;
}
.leaderboard table {
width: 100%;
border-collapse: collapse;
}
.leaderboard th, .leaderboard td {
padding: 10px;
border: 1px solid #ddd;
}
.leaderboard th {
background-color: #007BFF;
color: #fff;
}
</style>
</head>
<body>
<!-- Main Menu -->
<div id="menu" class="menu">
<h1>Dynamic Quiz Website</h1>
<p>Choose a topic and difficulty to start the quiz:</p>
<select id="difficulty">
<option value="easy">Easy</option>
<option value="medium">Medium</option>
<option value="hard">Hard</option>
</select>
<button onclick="startQuiz('math')">Math</button>
<button onclick="startQuiz('chemistry')">Chemistry</button>
<button onclick="startQuiz('biology')">Biology</button>
<button onclick="startQuiz('science')">Science</button>
<button onclick="startQuiz('history')">History/Social Studies</button>
<button onclick="startQuiz('language')">Language</button>
<button onclick="showLeaderboard()">Leaderboard</button>
</div>
<!-- Quiz Section -->
<div id="quiz" class="quiz" style="display: none;">
<h1 id="quizTopic"></h1>
<div class="progress-bar">
<div class="progress" id="progress"></div>
</div>
<div class="timer" id="timer">Time left: 10</div>
<div class="question">
<p id="questionText"></p>
</div>
<div class="options" id="options"></div>
<div class="hint" onclick="useHint()">Get a hint (-2 points)</div>
<button onclick="backToMenu()">Back to Menu</button>
</div>
<!-- Score Section -->
<div id="score" class="score" style="display: none;">
<h1>Your Score</h1>
<p id="scoreText"></p>
<button onclick="backToMenu()">Back to Menu</button>
<button onclick="shareResult()">Share Result</button>
</div>
<!-- Leaderboard Section -->
<div id="leaderboard" class="leaderboard" style="display: none;">
<h1>Leaderboard</h1>
<table id="leaderboardTable">
<thead>
<tr>
<th>Rank</th>
<th>Username</th>
<th>Score</th>
</tr>
</thead>
<tbody>
<!-- Leaderboard data will be populated here -->
</tbody>
</table>
<button onclick="backToMenu()">Back to Menu</button>
</div>
<script>
let currentTopic = "";
let difficulty = "easy";
let score = 0;
let questionCount = 0;
let timer;
let timeLeft = 10;
let hintUsed = false;
let currentHint = "";
let correctAnswers = 0; // Track correct answers
// Leaderboard data (mock data for now)
const leaderboardData = [
{ username: "Alice", score: 95 },
{ username: "Bob", score: 90 },
{ username: "Charlie", score: 85 },
];
// Function to generate random math questions based on difficulty
function generateMathQuestion() {
const num1 = Math.floor(Math.random() * (difficulty === "easy" ? 10 : difficulty === "medium" ? 20 : 50)) + 1;
const num2 = Math.floor(Math.random() * (difficulty === "easy" ? 10 : difficulty === "medium" ? 20 : 50)) + 1;
const operators = ["+", "-", "*"];
const operator = operators[Math.floor(Math.random() * operators.length)];
const question = `What is ${num1} ${operator} ${num2}?`;
const answer = eval(`${num1} ${operator} ${num2}`).toString();
const options = [answer];
while (options.length < 4) {
const randomOption = Math.floor(Math.random() * (difficulty === "easy" ? 20 : difficulty === "medium" ? 50 : 100)) + 1;
if (!options.includes(randomOption.toString())) {
options.push(randomOption.toString());
}
}
options.sort(() => Math.random() - 0.5); // Shuffle options
// Hint for math question
currentHint = "Think about the order of operations (PEMDAS/BODMAS).";
return { question, options, answer };
}
// Function to generate random chemistry questions
function generateChemistryQuestion() {
const questions = [
{
question: "What is the chemical formula for water?",
answer: "H2O",
options: ["H2O", "CO2", "O2", "NaCl"],
hint: "This compound is essential for life and covers most of the Earth's surface."
},
{
question: "What is the common name for H2O?",
answer: "Water",
options: ["Water", "Carbon Dioxide", "Oxygen", "Sodium Chloride"],
hint: "This compound is commonly found in lakes, rivers, and oceans."
},
{
question: "Which compound is a greenhouse gas?",
answer: "CO2",
options: ["H2O", "CO2", "O2", "NaCl"],
hint: "This compound is released when fossil fuels are burned."
},
{
question: "Balance the equation: H2 + O2 β H2O.",
answer: "2H2 + O2 β 2H2O",
options: ["H2 + O2 β H2O", "2H2 + O2 β 2H2O", "H2 + 2O2 β 2H2O", "2H2 + 2O2 β 2H2O"],
hint: "Remember that the number of atoms on both sides of the equation must be equal."
}
];
const randomQuestion = questions[Math.floor(Math.random() * questions.length)];
currentHint = randomQuestion.hint;
return randomQuestion;
}
// Function to generate random biology questions
function generateBiologyQuestion() {
const questions = [
{
question: "Which organelle is known as the powerhouse of the cell?",
answer: "Mitochondria",
options: ["Nucleus", "Mitochondria", "Ribosome", "Chloroplast"],
hint: "This organelle produces energy in the form of ATP."
},
{
question: "What is the function of the ribosome?",
answer: "Protein synthesis",
options: ["Energy production", "Protein synthesis", "DNA replication", "Waste removal"],
hint: "This organelle is responsible for creating proteins."
},
{
question: "Which part of the human body is responsible for pumping blood?",
answer: "Heart",
options: ["Brain", "Heart", "Liver", "Lungs"],
hint: "This organ is part of the circulatory system."
},
{
question: "What is the largest organ in the human body?",
answer: "Skin",
options: ["Liver", "Skin", "Brain", "Heart"],
hint: "This organ protects the body from external damage."
}
];
const randomQuestion = questions[Math.floor(Math.random() * questions.length)];
currentHint = randomQuestion.hint;
return randomQuestion;
}
// Function to generate random history/social studies questions
function generateHistoryQuestion() {
const questions = [
{
question: "Who was the first President of the United States?",
answer: "George Washington",
options: ["Thomas Jefferson", "George Washington", "Abraham Lincoln", "John Adams"],
hint: "He is often referred to as the 'Father of His Country'."
},
{
question: "In which year did World War II end?",
answer: "1945",
options: ["1939", "1945", "1950", "1960"],
hint: "The war ended after the surrender of Japan."
},
{
question: "Which document declared the independence of the United States?",
answer: "Declaration of Independence",
options: ["Constitution", "Declaration of Independence", "Bill of Rights", "Magna Carta"],
hint: "This document was adopted on July 4, 1776."
},
{
question: "Who wrote 'The Communist Manifesto'?",
answer: "Karl Marx and Friedrich Engels",
options: ["Karl Marx and Friedrich Engels", "Vladimir Lenin", "Joseph Stalin", "Mao Zedong"],
hint: "This book was published in 1848."
}
];
const randomQuestion = questions[Math.floor(Math.random() * questions.length)];
currentHint = randomQuestion.hint;
return randomQuestion;
}
// Function to generate random language questions
function generateLanguageQuestion() {
const questions = [
{
question: "What is the past tense of 'go'?",
answer: "Went",
options: ["Goed", "Went", "Gone", "Going"],
hint: "This verb is irregular and does not follow the standard past tense rules."
},
{
question: "What is the plural of 'child'?",
answer: "Children",
options: ["Childs", "Children", "Childen", "Childe"],
hint: "This word is an irregular plural."
},
{
question: "Which word is a synonym for 'happy'?",
answer: "Joyful",
options: ["Sad", "Joyful", "Angry", "Bored"],
hint: "This word means feeling or showing pleasure."
},
{
question: "What is the main verb in the sentence: 'She is reading a book.'?",
answer: "Reading",
options: ["She", "Is", "Reading", "Book"],
hint: "This word describes the action in the sentence."
}
];
const randomQuestion = questions[Math.floor(Math.random() * questions.length)];
currentHint = randomQuestion.hint;
return randomQuestion;
}
// Function to start the quiz
function startQuiz(topic) {
currentTopic = topic;
difficulty = document.getElementById("difficulty").value;
score = 0;
questionCount = 0;
correctAnswers = 0; // Reset correct answers counter
document.getElementById("menu").style.display = "none";
document.getElementById("quiz").style.display = "block";
document.getElementById("quizTopic").innerText = topic.charAt(0).toUpperCase() + topic.slice(1);
timeLeft = 10; // Reset timeLeft
document.getElementById("timer").innerText = `Time left: ${timeLeft}`;
loadQuestion();
startTimer();
}
// Function to load the next question
function loadQuestion() {
let questionData;
switch (currentTopic) {
case "math":
questionData = generateMathQuestion();
break;
case "chemistry":
questionData = generateChemistryQuestion();
break;
case "biology":
questionData = generateBiologyQuestion();
break;
case "history":
questionData = generateHistoryQuestion();
break;
case "language":
questionData = generateLanguageQuestion();
break;
default:
questionData = { question: "No question available", options: [], answer: "" };
}
document.getElementById("questionText").innerText = questionData.question;
const optionsDiv = document.getElementById("options");
optionsDiv.innerHTML = "";
questionData.options.forEach(option => {
const button = document.createElement("button");
button.innerText = option;
button.onclick = () => checkAnswer(option, questionData.answer);
optionsDiv.appendChild(button);
});
updateProgressBar();
}
// Function to check the answer
function checkAnswer(selected, correct) {
if (selected === correct) {
correctAnswers++; // Increment correct answers counter
score += hintUsed ? 1 : 2; // Deduct points if hint was used
}
hintUsed = false;
questionCount++;
if (questionCount % 10 === 0) {
showScore();
} else {
loadQuestion();
}
}
// Function to show the score
function showScore() {
clearInterval(timer);
document.getElementById("quiz").style.display = "none";
document.getElementById("score").style.display = "block";
document.getElementById("scoreText").innerText = `You scored ${correctAnswers * 5} points!`;
}
// Function to go back to the main menu
function backToMenu() {
clearInterval(timer);
document.getElementById("quiz").style.display = "none";
document.getElementById("score").style.display = "none";
document.getElementById("leaderboard").style.display = "none";
document.getElementById("menu").style.display = "block";
}
// Function to start the timer
function startTimer() {
timer = setInterval(() => {
timeLeft--;
document.getElementById("timer").innerText = `Time left: ${timeLeft}`;
if (timeLeft <= 0 || questionCount >= 10) { // Check if time is up OR 10 questions have been answered
clearInterval(timer);
showScore();
}
}, 1000);
}
// Function to update the progress bar
function updateProgressBar() {
const progress = (questionCount / 10) * 100;
document.getElementById("progress").style.width = `${progress}%`;
}
// Function to use a hint
function useHint() {
hintUsed = true;
alert(`Hint: ${currentHint}`);
}
// Function to show the leaderboard
function showLeaderboard() {
document.getElementById("menu").style.display = "none";
document.getElementById("leaderboard").style.display = "block";
const leaderboardTable = document.getElementById("leaderboardTable").getElementsByTagName("tbody")[0];
leaderboardTable.innerHTML = "";
leaderboardData.sort((a, b) => b.score - a.score).forEach((entry, index) => {
const row = leaderboardTable.insertRow();
row.insertCell().innerText = index + 1;
row.insertCell().innerText = entry.username;
row.insertCell().innerText = entry.score;
});
}
// Function to share the result on social media
function shareResult() {
const shareText = `I scored ${score} points on the Dynamic Quiz Website! Can you beat me?`;
const shareUrl = window.location.href;
window.open(`https://twitter.com/intent/tweet?text=${encodeURIComponent(shareText)}&url=${encodeURIComponent(shareUrl)}`, '_blank');
}
</script>
</body>
</html>
|