Spaces:
Running
Running
File size: 38,140 Bytes
eeb2dc7 | 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 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CodeMaster - Learn Programming Easily</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
.language-dropdown:hover .language-menu {
display: block;
}
.lesson-card:hover {
transform: translateY(-5px);
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
}
.progress-ring__circle {
transition: stroke-dashoffset 0.5s;
transform: rotate(-90deg);
transform-origin: 50% 50%;
}
.quiz-option:hover {
background-color: #f3f4f6;
}
.quiz-option.selected {
background-color: #3b82f6;
color: white;
}
.quiz-option.correct {
background-color: #10b981;
color: white;
}
.quiz-option.incorrect {
background-color: #ef4444;
color: white;
}
</style>
</head>
<body class="bg-gray-50 font-sans">
<!-- Header -->
<header class="bg-white shadow-sm sticky top-0 z-10">
<div class="container mx-auto px-4 py-3 flex justify-between items-center">
<div class="flex items-center space-x-2">
<i class="fas fa-code text-blue-600 text-2xl"></i>
<h1 class="text-xl font-bold text-gray-800">CodeMaster</h1>
</div>
<div class="flex items-center space-x-4">
<div class="language-dropdown relative">
<button id="languageBtn" class="flex items-center space-x-1 px-3 py-2 rounded-md hover:bg-gray-100">
<i class="fas fa-globe"></i>
<span>English</span>
<i class="fas fa-chevron-down text-xs"></i>
</button>
<div id="languageMenu" class="language-menu absolute right-0 mt-2 w-40 bg-white rounded-md shadow-lg py-1 z-20 hidden">
<a href="#" data-lang="en" class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100">English</a>
<a href="#" data-lang="ar" class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100">العربية</a>
<a href="#" data-lang="es" class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100">Español</a>
<a href="#" data-lang="fr" class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100">Français</a>
</div>
</div>
<button id="themeToggle" class="p-2 rounded-full hover:bg-gray-100">
<i class="fas fa-moon"></i>
</button>
<button id="authBtn" class="bg-blue-600 text-white px-4 py-2 rounded-md hover:bg-blue-700 transition">
Sign In
</button>
</div>
</div>
</header>
<!-- Hero Section -->
<section class="bg-gradient-to-r from-blue-600 to-indigo-700 text-white py-16">
<div class="container mx-auto px-4 text-center">
<h1 class="text-4xl md:text-5xl font-bold mb-4">Learn Programming the Easy Way</h1>
<p class="text-xl mb-8 max-w-2xl mx-auto">Master coding skills with interactive lessons and quizzes. Start your journey today!</p>
<div class="flex flex-col sm:flex-row justify-center gap-4">
<button class="bg-white text-blue-600 px-6 py-3 rounded-md font-medium hover:bg-gray-100 transition">Start Learning</button>
<button class="border-2 border-white text-white px-6 py-3 rounded-md font-medium hover:bg-white hover:text-blue-600 transition">Explore Courses</button>
</div>
</div>
</section>
<!-- Main Content -->
<main class="container mx-auto px-4 py-12">
<div class="flex flex-col lg:flex-row gap-8">
<!-- Sidebar -->
<aside class="lg:w-1/4 bg-white rounded-lg shadow-md p-6 h-fit sticky top-24">
<h2 class="text-xl font-bold mb-4 text-gray-800">Courses</h2>
<div class="space-y-2">
<div class="course-category">
<button class="flex justify-between items-center w-full px-3 py-2 rounded-md hover:bg-gray-100">
<span class="font-medium">Web Development</span>
<i class="fas fa-chevron-down text-xs"></i>
</button>
<div class="pl-4 mt-1 space-y-1">
<a href="#" class="block px-3 py-1 text-sm rounded-md hover:bg-gray-100">HTML & CSS</a>
<a href="#" class="block px-3 py-1 text-sm rounded-md hover:bg-gray-100">JavaScript</a>
<a href="#" class="block px-3 py-1 text-sm rounded-md hover:bg-gray-100">React</a>
</div>
</div>
<div class="course-category">
<button class="flex justify-between items-center w-full px-3 py-2 rounded-md hover:bg-gray-100">
<span class="font-medium">Mobile Development</span>
<i class="fas fa-chevron-down text-xs"></i>
</button>
</div>
<div class="course-category">
<button class="flex justify-between items-center w-full px-3 py-2 rounded-md hover:bg-gray-100">
<span class="font-medium">Data Science</span>
<i class="fas fa-chevron-down text-xs"></i>
</button>
</div>
</div>
<div class="mt-8">
<h3 class="font-bold mb-3 text-gray-800">Your Progress</h3>
<div class="flex items-center justify-center">
<div class="relative w-32 h-32">
<svg class="w-full h-full" viewBox="0 0 100 100">
<circle class="text-gray-200" stroke-width="8" stroke="currentColor" fill="transparent" r="40" cx="50" cy="50" />
<circle class="text-blue-600 progress-ring__circle" stroke-width="8" stroke-linecap="round" stroke="currentColor" fill="transparent" r="40" cx="50" cy="50" stroke-dasharray="251.2" stroke-dashoffset="125.6" />
</svg>
<div class="absolute inset-0 flex items-center justify-center flex-col">
<span class="text-2xl font-bold">50%</span>
<span class="text-xs text-gray-500">Completed</span>
</div>
</div>
</div>
<div class="mt-4 space-y-2">
<div class="flex justify-between text-sm">
<span>Completed Lessons</span>
<span>12/24</span>
</div>
<div class="w-full bg-gray-200 rounded-full h-2">
<div class="bg-blue-600 h-2 rounded-full" style="width: 50%"></div>
</div>
</div>
</div>
</aside>
<!-- Lessons Content -->
<div class="lg:w-3/4">
<!-- Breadcrumbs -->
<nav class="flex mb-6" aria-label="Breadcrumb">
<ol class="inline-flex items-center space-x-1 md:space-x-3">
<li class="inline-flex items-center">
<a href="#" class="inline-flex items-center text-sm font-medium text-gray-700 hover:text-blue-600">
<i class="fas fa-home mr-2"></i>
Home
</a>
</li>
<li>
<div class="flex items-center">
<i class="fas fa-chevron-right text-gray-400 text-xs"></i>
<a href="#" class="ml-1 text-sm font-medium text-gray-700 hover:text-blue-600 md:ml-2">Web Development</a>
</div>
</li>
<li aria-current="page">
<div class="flex items-center">
<i class="fas fa-chevron-right text-gray-400 text-xs"></i>
<span class="ml-1 text-sm font-medium text-gray-500 md:ml-2">JavaScript Basics</span>
</div>
</li>
</ol>
</nav>
<!-- Current Lesson -->
<div class="bg-white rounded-lg shadow-md overflow-hidden mb-8">
<div class="p-6">
<div class="flex justify-between items-center mb-4">
<h2 class="text-2xl font-bold text-gray-800">Variables and Data Types</h2>
<span class="bg-green-100 text-green-800 text-xs font-medium px-2.5 py-0.5 rounded">Beginner</span>
</div>
<div class="prose max-w-none mb-6">
<p>In JavaScript, variables are containers for storing data values. JavaScript uses the <code>var</code>, <code>let</code>, and <code>const</code> keywords to declare variables.</p>
<h3 class="text-xl font-semibold mt-4">Variable Declaration</h3>
<pre class="bg-gray-100 p-4 rounded-md overflow-x-auto">
<code>
// Using var (old way, not recommended)
var name = "John";
// Using let (block-scoped, can be reassigned)
let age = 25;
// Using const (block-scoped, cannot be reassigned)
const PI = 3.14;
</code>
</pre>
<h3 class="text-xl font-semibold mt-4">Data Types</h3>
<p>JavaScript has several data types:</p>
<ul class="list-disc pl-5">
<li><strong>String:</strong> Textual data (e.g., "Hello World")</li>
<li><strong>Number:</strong> Numeric data (e.g., 42, 3.14)</li>
<li><strong>Boolean:</strong> True or false values</li>
<li><strong>Object:</strong> Collections of key-value pairs</li>
<li><strong>Array:</strong> Ordered lists of values</li>
<li><strong>Null:</strong> Intentional absence of any object value</li>
<li><strong>Undefined:</strong> Variable that has not been assigned a value</li>
</ul>
<div class="bg-blue-50 border-l-4 border-blue-500 p-4 mt-4">
<div class="flex">
<div class="flex-shrink-0">
<i class="fas fa-lightbulb text-blue-500"></i>
</div>
<div class="ml-3">
<p class="text-sm text-blue-700">
<strong>Tip:</strong> Always use <code>const</code> by default, and only use <code>let</code> when you know the variable's value will change. Avoid <code>var</code> in modern JavaScript.
</p>
</div>
</div>
</div>
</div>
<div class="flex justify-between mt-8">
<button class="flex items-center text-blue-600 hover:text-blue-800">
<i class="fas fa-arrow-left mr-2"></i>
Previous Lesson
</button>
<button id="startQuizBtn" class="bg-blue-600 text-white px-4 py-2 rounded-md hover:bg-blue-700 transition">
Take Quiz
<i class="fas fa-arrow-right ml-2"></i>
</button>
</div>
</div>
</div>
<!-- Lesson Navigation -->
<div class="bg-white rounded-lg shadow-md overflow-hidden mb-8">
<div class="p-6">
<h3 class="text-lg font-semibold mb-4">Course Lessons</h3>
<div class="space-y-3">
<div class="flex items-center p-3 rounded-md bg-blue-50 border border-blue-200">
<div class="flex-shrink-0 w-8 h-8 rounded-full bg-blue-600 text-white flex items-center justify-center">
<span>1</span>
</div>
<div class="ml-3 flex-1">
<h4 class="text-sm font-medium">Introduction to JavaScript</h4>
<p class="text-xs text-gray-500">Completed</p>
</div>
<i class="fas fa-check text-green-500"></i>
</div>
<div class="flex items-center p-3 rounded-md bg-blue-50 border border-blue-200">
<div class="flex-shrink-0 w-8 h-8 rounded-full bg-blue-600 text-white flex items-center justify-center">
<span>2</span>
</div>
<div class="ml-3 flex-1">
<h4 class="text-sm font-medium">Variables and Data Types</h4>
<p class="text-xs text-gray-500">Current Lesson</p>
</div>
<i class="fas fa-play text-blue-500"></i>
</div>
<div class="flex items-center p-3 rounded-md hover:bg-gray-50 cursor-pointer">
<div class="flex-shrink-0 w-8 h-8 rounded-full bg-gray-200 text-gray-600 flex items-center justify-center">
<span>3</span>
</div>
<div class="ml-3 flex-1">
<h4 class="text-sm font-medium">Operators and Expressions</h4>
<p class="text-xs text-gray-500">Locked</p>
</div>
<i class="fas fa-lock text-gray-400"></i>
</div>
<div class="flex items-center p-3 rounded-md hover:bg-gray-50 cursor-pointer">
<div class="flex-shrink-0 w-8 h-8 rounded-full bg-gray-200 text-gray-600 flex items-center justify-center">
<span>4</span>
</div>
<div class="ml-3 flex-1">
<h4 class="text-sm font-medium">Control Flow</h4>
<p class="text-xs text-gray-500">Locked</p>
</div>
<i class="fas fa-lock text-gray-400"></i>
</div>
</div>
</div>
</div>
</div>
</div>
</main>
<!-- Quiz Modal -->
<div id="quizModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden">
<div class="bg-white rounded-lg shadow-xl w-full max-w-2xl max-h-[90vh] overflow-y-auto">
<div class="p-6">
<div class="flex justify-between items-center mb-6">
<h3 class="text-xl font-bold">Lesson Quiz</h3>
<button id="closeQuizModal" class="text-gray-500 hover:text-gray-700">
<i class="fas fa-times"></i>
</button>
</div>
<div class="mb-6">
<div class="flex justify-between text-sm mb-1">
<span>Progress</span>
<span><span id="currentQuestion">1</span>/5</span>
</div>
<div class="w-full bg-gray-200 rounded-full h-2">
<div id="quizProgress" class="bg-blue-600 h-2 rounded-full" style="width: 20%"></div>
</div>
</div>
<div id="quizContent">
<div class="question mb-6">
<h4 class="text-lg font-semibold mb-4">1. Which keyword is used to declare a variable that cannot be reassigned?</h4>
<div class="space-y-3">
<div class="quiz-option p-3 border rounded-md cursor-pointer" data-correct="false">
<span>var</span>
</div>
<div class="quiz-option p-3 border rounded-md cursor-pointer" data-correct="false">
<span>let</span>
</div>
<div class="quiz-option p-3 border rounded-md cursor-pointer" data-correct="true">
<span>const</span>
</div>
<div class="quiz-option p-3 border rounded-md cursor-pointer" data-correct="false">
<span>static</span>
</div>
</div>
</div>
<div class="question mb-6 hidden">
<h4 class="text-lg font-semibold mb-4">2. What will be the output of: <code>console.log(typeof 42);</code></h4>
<div class="space-y-3">
<div class="quiz-option p-3 border rounded-md cursor-pointer" data-correct="false">
<span>"string"</span>
</div>
<div class="quiz-option p-3 border rounded-md cursor-pointer" data-correct="true">
<span>"number"</span>
</div>
<div class="quiz-option p-3 border rounded-md cursor-pointer" data-correct="false">
<span>"integer"</span>
</div>
<div class="quiz-option p-3 border rounded-md cursor-pointer" data-correct="false">
<span>"float"</span>
</div>
</div>
</div>
<div class="question mb-6 hidden">
<h4 class="text-lg font-semibold mb-4">3. Which of the following is NOT a valid JavaScript data type?</h4>
<div class="space-y-3">
<div class="quiz-option p-3 border rounded-md cursor-pointer" data-correct="false">
<span>Boolean</span>
</div>
<div class="quiz-option p-3 border rounded-md cursor-pointer" data-correct="false">
<span>Undefined</span>
</div>
<div class="quiz-option p-3 border rounded-md cursor-pointer" data-correct="true">
<span>Character</span>
</div>
<div class="quiz-option p-3 border rounded-md cursor-pointer" data-correct="false">
<span>Symbol</span>
</div>
</div>
</div>
<div class="question mb-6 hidden">
<h4 class="text-lg font-semibold mb-4">4. What is the correct way to declare a variable in modern JavaScript?</h4>
<div class="space-y-3">
<div class="quiz-option p-3 border rounded-md cursor-pointer" data-correct="false">
<span>variable name = "Alice";</span>
</div>
<div class="quiz-option p-3 border rounded-md cursor-pointer" data-correct="true">
<span>let name = "Alice";</span>
</div>
<div class="quiz-option p-3 border rounded-md cursor-pointer" data-correct="false">
<span>v name = "Alice";</span>
</div>
<div class="quiz-option p-3 border rounded-md cursor-pointer" data-correct="false">
<span>string name = "Alice";</span>
</div>
</div>
</div>
<div class="question mb-6 hidden">
<h4 class="text-lg font-semibold mb-4">5. Which of the following is a valid variable name in JavaScript?</h4>
<div class="space-y-3">
<div class="quiz-option p-3 border rounded-md cursor-pointer" data-correct="false">
<span>2ndPlace</span>
</div>
<div class="quiz-option p-3 border rounded-md cursor-pointer" data-correct="false">
<span>first-name</span>
</div>
<div class="quiz-option p-3 border rounded-md cursor-pointer" data-correct="true">
<span>firstName</span>
</div>
<div class="quiz-option p-3 border rounded-md cursor-pointer" data-correct="false">
<span>let</span>
</div>
</div>
</div>
</div>
<div class="flex justify-between mt-8">
<button id="prevQuestionBtn" class="text-blue-600 hover:text-blue-800 disabled:opacity-50 disabled:cursor-not-allowed" disabled>
<i class="fas fa-arrow-left mr-2"></i>
Previous
</button>
<button id="nextQuestionBtn" class="bg-blue-600 text-white px-4 py-2 rounded-md hover:bg-blue-700 transition">
Next Question
<i class="fas fa-arrow-right ml-2"></i>
</button>
</div>
</div>
</div>
</div>
<!-- Quiz Results Modal -->
<div id="resultsModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden">
<div class="bg-white rounded-lg shadow-xl w-full max-w-md">
<div class="p-6 text-center">
<div class="mx-auto flex items-center justify-center h-12 w-12 rounded-full bg-green-100 mb-4">
<i class="fas fa-trophy text-green-600 text-xl"></i>
</div>
<h3 class="text-lg font-medium text-gray-900 mb-2">Quiz Completed!</h3>
<div class="mt-2">
<p class="text-sm text-gray-500">You scored <span id="quizScore" class="font-bold">0</span> out of 5</p>
</div>
<div class="mt-6">
<div class="w-full bg-gray-200 rounded-full h-2.5 mb-4">
<div id="scoreBar" class="bg-blue-600 h-2.5 rounded-full" style="width: 0%"></div>
</div>
</div>
<div class="mt-6 flex justify-center gap-4">
<button id="retakeQuizBtn" class="px-4 py-2 border border-gray-300 rounded-md text-sm font-medium text-gray-700 hover:bg-gray-50">
Retake Quiz
</button>
<button id="continueLearningBtn" class="px-4 py-2 bg-blue-600 text-white rounded-md text-sm font-medium hover:bg-blue-700">
Continue Learning
</button>
</div>
</div>
</div>
</div>
<!-- Footer -->
<footer class="bg-gray-800 text-white py-12">
<div class="container mx-auto px-4">
<div class="grid grid-cols-1 md:grid-cols-4 gap-8">
<div>
<h3 class="text-lg font-semibold mb-4">CodeMaster</h3>
<p class="text-gray-400">Learn programming the easy way with interactive lessons and quizzes.</p>
</div>
<div>
<h4 class="text-lg font-semibold mb-4">Courses</h4>
<ul class="space-y-2">
<li><a href="#" class="text-gray-400 hover:text-white">Web Development</a></li>
<li><a href="#" class="text-gray-400 hover:text-white">Mobile Development</a></li>
<li><a href="#" class="text-gray-400 hover:text-white">Data Science</a></li>
<li><a href="#" class="text-gray-400 hover:text-white">Algorithms</a></li>
</ul>
</div>
<div>
<h4 class="text-lg font-semibold mb-4">Resources</h4>
<ul class="space-y-2">
<li><a href="#" class="text-gray-400 hover:text-white">Documentation</a></li>
<li><a href="#" class="text-gray-400 hover:text-white">Blog</a></li>
<li><a href="#" class="text-gray-400 hover:text-white">Community</a></li>
<li><a href="#" class="text-gray-400 hover:text-white">Support</a></li>
</ul>
</div>
<div>
<h4 class="text-lg font-semibold mb-4">Connect</h4>
<div class="flex space-x-4">
<a href="#" class="text-gray-400 hover:text-white"><i class="fab fa-facebook-f"></i></a>
<a href="#" class="text-gray-400 hover:text-white"><i class="fab fa-twitter"></i></a>
<a href="#" class="text-gray-400 hover:text-white"><i class="fab fa-instagram"></i></a>
<a href="#" class="text-gray-400 hover:text-white"><i class="fab fa-linkedin-in"></i></a>
<a href="#" class="text-gray-400 hover:text-white"><i class="fab fa-github"></i></a>
</div>
<div class="mt-4">
<p class="text-gray-400">Subscribe to our newsletter</p>
<div class="mt-2 flex">
<input type="email" placeholder="Your email" class="px-3 py-2 bg-gray-700 text-white rounded-l-md focus:outline-none focus:ring-1 focus:ring-blue-500 w-full">
<button class="bg-blue-600 text-white px-4 py-2 rounded-r-md hover:bg-blue-700">Subscribe</button>
</div>
</div>
</div>
</div>
<div class="border-t border-gray-700 mt-8 pt-8 text-center text-gray-400 text-sm">
<p>© 2023 CodeMaster. All rights reserved.</p>
</div>
</div>
</footer>
<script>
// Language switcher
const languageBtn = document.getElementById('languageBtn');
const languageMenu = document.getElementById('languageMenu');
const languageLinks = document.querySelectorAll('#languageMenu a');
languageBtn.addEventListener('click', () => {
languageMenu.classList.toggle('hidden');
});
languageLinks.forEach(link => {
link.addEventListener('click', (e) => {
e.preventDefault();
const lang = link.getAttribute('data-lang');
languageBtn.querySelector('span').textContent = link.textContent;
languageMenu.classList.add('hidden');
// In a real app, you would change the language here
console.log(`Language changed to: ${lang}`);
});
});
// Theme toggle
const themeToggle = document.getElementById('themeToggle');
const icon = themeToggle.querySelector('i');
themeToggle.addEventListener('click', () => {
document.documentElement.classList.toggle('dark');
if (document.documentElement.classList.contains('dark')) {
icon.classList.remove('fa-moon');
icon.classList.add('fa-sun');
localStorage.setItem('theme', 'dark');
} else {
icon.classList.remove('fa-sun');
icon.classList.add('fa-moon');
localStorage.setItem('theme', 'light');
}
});
// Check for saved theme preference
if (localStorage.getItem('theme') === 'dark' || (!localStorage.getItem('theme') && window.matchMedia('(prefers-color-scheme: dark)').matches)) {
document.documentElement.classList.add('dark');
icon.classList.remove('fa-moon');
icon.classList.add('fa-sun');
}
// Quiz functionality
const quizModal = document.getElementById('quizModal');
const startQuizBtn = document.getElementById('startQuizBtn');
const closeQuizModal = document.getElementById('closeQuizModal');
const nextQuestionBtn = document.getElementById('nextQuestionBtn');
const prevQuestionBtn = document.getElementById('prevQuestionBtn');
const currentQuestionDisplay = document.getElementById('currentQuestion');
const quizProgress = document.getElementById('quizProgress');
const quizContent = document.getElementById('quizContent');
const questions = document.querySelectorAll('.question');
const quizOptions = document.querySelectorAll('.quiz-option');
const resultsModal = document.getElementById('resultsModal');
const quizScore = document.getElementById('quizScore');
const scoreBar = document.getElementById('scoreBar');
const retakeQuizBtn = document.getElementById('retakeQuizBtn');
const continueLearningBtn = document.getElementById('continueLearningBtn');
let currentQuestion = 0;
let score = 0;
let userAnswers = Array(questions.length).fill(null);
startQuizBtn.addEventListener('click', () => {
quizModal.classList.remove('hidden');
document.body.style.overflow = 'hidden';
showQuestion(0);
});
closeQuizModal.addEventListener('click', () => {
quizModal.classList.add('hidden');
document.body.style.overflow = 'auto';
});
nextQuestionBtn.addEventListener('click', () => {
if (currentQuestion < questions.length - 1) {
currentQuestion++;
showQuestion(currentQuestion);
} else {
showResults();
}
});
prevQuestionBtn.addEventListener('click', () => {
if (currentQuestion > 0) {
currentQuestion--;
showQuestion(currentQuestion);
}
});
quizOptions.forEach(option => {
option.addEventListener('click', () => {
const questionContainer = option.closest('.question');
const options = questionContainer.querySelectorAll('.quiz-option');
// Remove selected class from all options in this question
options.forEach(opt => {
opt.classList.remove('selected');
});
// Add selected class to clicked option
option.classList.add('selected');
// Store user answer
const questionIndex = Array.from(questions).indexOf(questionContainer);
userAnswers[questionIndex] = option.getAttribute('data-correct') === 'true';
// Enable next button
nextQuestionBtn.disabled = false;
});
});
retakeQuizBtn.addEventListener('click', () => {
resultsModal.classList.add('hidden');
currentQuestion = 0;
score = 0;
userAnswers = Array(questions.length).fill(null);
resetQuiz();
showQuestion(0);
quizModal.classList.remove('hidden');
});
continueLearningBtn.addEventListener('click', () => {
resultsModal.classList.add('hidden');
quizModal.classList.add('hidden');
document.body.style.overflow = 'auto';
});
function showQuestion(index) {
// Hide all questions
questions.forEach(question => {
question.classList.add('hidden');
});
// Show current question
questions[index].classList.remove('hidden');
// Update progress display
currentQuestionDisplay.textContent = index + 1;
const progressPercent = ((index + 1) / questions.length) * 100;
quizProgress.style.width = `${progressPercent}%`;
// Update button states
prevQuestionBtn.disabled = index === 0;
if (index === questions.length - 1) {
nextQuestionBtn.innerHTML = 'Finish Quiz <i class="fas fa-check ml-2"></i>';
} else {
nextQuestionBtn.innerHTML = 'Next Question <i class="fas fa-arrow-right ml-2"></i>';
}
// Disable next button if no answer selected for current question
const currentOptions = questions[index].querySelectorAll('.quiz-option');
const hasSelected = Array.from(currentOptions).some(opt => opt.classList.contains('selected'));
nextQuestionBtn.disabled = !hasSelected;
// Restore user's previous answer if exists
if (userAnswers[index] !== null) {
currentOptions.forEach(opt => {
if (opt.classList.contains('selected')) {
opt.classList.remove('selected');
}
});
// In a real app, you would restore the user's actual selected answer
// This is simplified for the demo
currentOptions[0].classList.add('selected');
}
}
function showResults() {
// Calculate score
score = userAnswers.filter(answer => answer === true).length;
// Update results display
quizScore.textContent = score;
const scorePercent = (score / questions.length) * 100;
scoreBar.style.width = `${scorePercent}%`;
// Close quiz modal and show results
quizModal.classList.add('hidden');
resultsModal.classList.remove('hidden');
}
function resetQuiz() {
// Reset all options
quizOptions.forEach(option => {
option.classList.remove('selected', 'correct', 'incorrect');
});
// Reset progress
currentQuestionDisplay.textContent = '1';
quizProgress.style.width = '20%';
nextQuestionBtn.innerHTML = 'Next Question <i class="fas fa-arrow-right ml-2"></i>';
nextQuestionBtn.disabled = true;
prevQuestionBtn.disabled = true;
}
// Close modals when clicking outside
window.addEventListener('click', (e) => {
if (e.target === quizModal) {
quizModal.classList.add('hidden');
document.body.style.overflow = 'auto';
}
if (e.target === resultsModal) {
resultsModal.classList.add('hidden');
document.body.style.overflow = 'auto';
}
});
</script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=mohamed7869/learning-coding" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html> |