<!-- wp:html --> <!DOCTYPE html> <html lang="hi"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0"/> <title>MCQ Quiz</title> <style> /* Basic CSS resets */ * { margin: 0; padding: 0; box-sizing: border-box; } body { font-family: Arial, sans-serif; background-color: #f1f8e9; color: #33691e; } .content-container { background-color: #dcedc8; padding: 5px; border-radius: 5px; max-width: auto; margin: 20px auto; box-shadow: 0 6px 12px rgba(0, 0, 0, 0.1); position: relative; } .header { background-color: #7cb342; color: #ffffff; text-align: center; padding: 20px; border-radius: 10px; margin-bottom: 20px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15); position: relative; } .header h1 { margin: 0; font-size: 28px; } /* Hamburger Menu Icon */ .hamburger { position: absolute; top: 8px; left: 8px; z-index: 1000; width: 20px; height: 15px; display: flex; flex-direction: column; justify-content: space-between; cursor: pointer; } .hamburger-line { height: 3px; background-color: #fff; border-radius: 2px; } /* Sidebar (Question Nav) */ #questionNavOverlay { position: fixed; top: 0; left: -250px; /* hidden by default */ width: 250px; height: 100%; background-color: #fff; transition: left 0.3s ease-in-out; z-index: 2000; box-shadow: 2px 0 6px rgba(0,0,0,0.3); padding: 20px; overflow-y: auto; } #questionNavOverlay.show { left: 0; /* slide in */ } #questionNavTitle { margin-bottom: 10px; font-weight: bold; font-size: 1.1rem; } .question-nav { display: flex; flex-wrap: wrap; gap: 5px; } .circle-number { width: 30px; height: 30px; border-radius: 50%; background-color: #ccc; color: #000; display: flex; justify-content: center; align-items: center; cursor: pointer; user-select: none; /* Prevent text selection */ transition: background-color 0.2s; } .circle-number:hover { background-color: #aaa; } .circle-number.active { background-color: #4CAF50; color: #fff; } /* Quiz Container */ .quiz-container { background-color: #fff; border-radius: 10px; padding: 5px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); max-width: auto; width: 100%; margin: 0 auto; text-align: center; position: relative; } .question-counter { font-weight: bold; padding: 5px 10px; border-radius: 5px; background-color: #d9edf7; position: absolute; top: 10px; left: 10px; } /* Timer display */ .timer { font-weight: bold; padding: 5px 10px; border-radius: 5px; background-color: #ffcccb; position: absolute; top: 10px; right: 10px; } .question { font-size: 1.2rem; margin-top: 40px; margin-bottom: 20px; text-align: left; } .choices { display: flex; flex-direction: column; gap: 10px; } .choice { padding: 10px; background-color: #f0f0f0; border: 1px solid #ddd; border-radius: 5px; cursor: pointer; transition: background-color 0.3s, box-shadow 0.3s; } .choice:hover { background-color: #e0e0e0; box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); } .choice.selected { background-color: #28a745; /* More vivid green */ color: #fff; } .choice.correct { background-color: #28a745; /* More vivid green */ border-color: #28a745; color: #fff; } .choice.incorrect { background-color: #dc3545; /* More vivid red */ border-color: #dc3545; color: #fff; } .choice.disabled { cursor: not-allowed; pointer-events: none; opacity: 0.6; } .explanation { margin-top: 20px; text-align: left; background-color: #e7f3fe; padding: 15px; border-left: 5px solid #2196F3; border-radius: 5px; } .buttons { display: flex; justify-content: center; gap: 10px; margin-top: 20px; flex-wrap: wrap; } .btn { flex: 1 1 auto; padding: 8px 12px; background-color: #4CAF50; color: white; border: none; border-radius: 5px; cursor: pointer; font-size: 0.9rem; text-align: center; min-width: 100px; max-width: 150px; transition: none; } .btn.disabled { background-color: #cccccc; cursor: not-allowed; } .hidden { display: none; } /* Result Section */ #resultContent { text-align: center; margin-top: 20px; } .congrats { font-size: 1.5rem; color: #4CAF50; } .sad { font-size: 1.5rem; color: #d32f2f; } /* Popup Message (Optional) */ #popupMessage { position: fixed; top: 20px; left: 50%; transform: translateX(-50%); color: white; padding: 10px 20px; border-radius: 5px; font-size: 1rem; z-index: 5000; display: none; } #popupMessage.show { display: block; } #popupMessage.correct { background-color: #28a745; } #popupMessage.incorrect { background-color: #dc3545; } </style> </head> <body> <div class="content-container"> <div class="header"> <!-- Hamburger menu button --> <div class="hamburger" id="hamburgerBtn"> <div class="hamburger-line"></div> <div class="hamburger-line"></div> <div class="hamburger-line"></div> </div> <h1>MCQs Quiz</h1> </div> <!-- Sidebar (Question Nav) --> <div id="questionNavOverlay"> <div id="questionNavTitle">Questions</div> <div class="question-nav" id="questionNav"></div> </div> <!-- Quiz Container --> <div class="quiz-container" id="quizContent"> <div class="question-counter" id="questionCounter">1/3</div> <!-- Timer display here --> <div class="timer" id="timer">Time: 00:00</div> <div class="question" id="question">Loading question...</div> <div class="choices" id="choices"></div> <!-- Explanation and feedback --> <div class="explanation hidden" id="explanation"></div> <!-- Buttons for navigation and submission --> <div class="buttons"> <button class="btn" id="prevButton">Previous</button> <button class="btn" id="submitAnswerButton">Submit Answer</button> <button class="btn hidden" id="nextButton">Next</button> </div> </div> <!-- Result Section --> <div id="resultContent" class="hidden"> <h2>Quiz Completed</h2> <div id="resultMessage"></div> <p id="scoreMessage"></p> </div> </div> <!-- Optional Popup Message --> <div id="popupMessage" class="hidden"></div> <script> /***** JavaScript Code *****/ // Quiz data (sample) const quizData = [ { "question": "डेटा संरचना (Data Structure) से क्या आशय है?", "options": [ "एक विशेष प्रोग्रामिंग भाषा", "केवल हार्डवेयर का लेआउट", "डेटा को संग्रहित (Store) और व्यवस्थित (Organize) करने का एक तरीका, ताकि उस पर कुशलतापूर्वक संचालन (Operations) किए जा सकें", "केवल एल्गोरिदम" ], "correct": 2, "explanation": "डेटा संरचना का उद्देश्य डेटा को इस प्रकार संग्रहीत करना है कि उस पर सर्च, इनसर्शन, डिलीशन, अपडेट जैसे ऑपरेशनों को कम समय/मेमोरी में किया जा सके।" }, { "question": "एरे (Array) का सबसे बड़ा लाभ क्या है?", "options": [ "यह हमेशा खाली रहता है", "डेटा को मनमाने क्रम में रखने के लिए", "निरंतर मेमोरी ब्लॉक में एक ही डेटा टाइप के तत्वों को संग्रहीत करने से इंडेक्स के माध्यम से रैंडम ऐक्सेस (Random Access) संभव होता है", "एरे बदल ही नहीं सकता" ], "correct": 2, "explanation": "एरे में सभी तत्व एक ही टाइप के होते हैं और लगातार (Continuous) मेमोरी में होते हैं; इससे 0 आधारित इंडेक्स द्वारा किसी भी एलिमेंट तक पहुँच O(1) समय में हो सकती है।" }, { "question": "लिंक्ड लिस्ट (Linked List) में एक नोड (Node) क्या रखता है?", "options": [ "डेटा और एक अगला (next) पॉइंटर, संभवतः पिछला (prev) पॉइंटर भी (डबल लिंक्ड लिस्ट में)", "सिर्फ एक डेटा मान", "कोई एड्रेस नहीं", "एनोड और कैथाेड" ], "correct": 0, "explanation": "लिंक्ड लिस्ट में प्रत्येक नोड में डेटा और अगले नोड का एड्रेस (सिंगल लिंक्ड लिस्ट) होता है। डबल लिंक्ड लिस्ट में पिछले नोड का भी एड्रेस स्टोर किया जाता है।" }, { "question": "स्टैक (Stack) किस सिद्धांत पर कार्य करता है?", "options": [ "FIFO (First In First Out)", "LIFO (Last In First Out)", "Random Access", "सबसे पुराना एलिमेंट पहले निकले" ], "correct": 1, "explanation": "स्टैक एक LIFO संरचना है; आखिरी में जो तत्व डाला (push) गया, वही सबसे पहले (pop) निकाला जाता है।" }, { "question": "क्यू (Queue) किस सिद्धांत पर कार्य करता है?", "options": [ "LIFO (Last In First Out)", "FILFO (First In Last Fully Out)", "FIFO (First In First Out)", "Random Removal" ], "correct": 2, "explanation": "क्यू एक FIFO संरचना है; सबसे पहले जो तत्व एंटर करता है, वही सबसे पहले बाहर निकलता है।" }, { "question": "ट्री (Tree) डेटा संरचना में कौन-सा कथन सही है?", "options": [ "ट्री एक सीधी रेखा में तत्व रखता है", "ट्री में साइकल (चक्र) हो सकता है", "ट्री एकacyclic (बिना चक्र) ग्राफ है, जिसका एक रूट (root) व नोड्स के बीच पेरेंट-चाइल्ड संबंध होता है", "ट्री हमेशा बाइनरी ही होता है" ], "correct": 2, "explanation": "ट्री एक कनेक्टेड और acyclic संरचना है, जिसमें एक रूट नोड से पेरेंट-चाइल्ड रेलेशनशिप द्वारा सब नोड्स जुड़े होते हैं।" }, { "question": "ग्राफ (Graph) क्या है?", "options": [ "रेखीय डेटा संरचना", "नोड्स (Vertices) और किनारों (Edges) का संग्रह, जो संबंधों को निरूपित करता है", "कंप्यूटर का हार्डवेयर", "केवल ट्रैकिंग" ], "correct": 1, "explanation": "ग्राफ में वर्टिसेस (शिखर/Vertices) और एजेज़ (धार/Edges) होते हैं; इनसे किसी भी जटिल संबंध/नेटवर्क का मॉडल बनाया जा सकता है (सोशल नेटवर्क, सड़कों का नेटवर्क आदि)।" }, { "question": "हैशिंग (Hashing) का मुख्य उद्देश्य क्या है?", "options": [ "डेटा को सीक्वेंशियल सर्च से गुजरने देना", "मेमोरी बर्बाद करना", "कुंजी (Key) को एक हैश फंक्शन के माध्यम से परिवर्तित कर मैपिंग करना, ताकि इंसर्शन, सर्च, डिलीशन जल्दी (औसतन O(1)) हो सके", "डेटा को डिस्क में संग्रहीत करना" ], "correct": 2, "explanation": "हैश टेबल में एक हैश फंक्शन दिया जाता है, जो किसी कुंजी को टेबल इंडेक्स में बदल देता है; इससे औसत मामले में बहुत तेज़ एक्सेस संभव होता है।" }, { "question": "सॉर्टिंग (Sorting) अल्गोरिदम का कार्य क्या है?", "options": [ "डेटा में डुप्लिकेट ढूँढना", "डेटा को किसी क्रम (Ascending/Descending) में व्यवस्थित करना", "केवल लिंक्स को व्यवस्थित करना", "ग्राफ बनाना" ], "correct": 1, "explanation": "सॉर्टिंग एक प्रक्रिया है, जिसमें अव्यवस्थित डेटा को किसी परिभाषित क्रम (जैसे बढ़ते या घटते) में क्रमबद्ध किया जाता है।" }, { "question": "सर्चिंग (Searching) अल्गोरिदम का उद्देश्य क्या है?", "options": [ "डेटा स्ट्रक्चर को बदलना", "छुपे हुए मेमोरी लोकेशन्स को भरना", "कोई दिए गए कुंजी (Key) या तत्त्व को डेटा स्ट्रक्चर में खोज निकालना", "डेटा को रैंडम बनाना" ], "correct": 2, "explanation": "सर्चिंग विभिन्न एल्गोरिदम का उपयोग कर डेटा संरचना में किसी विशिष्ट कुंजी या वैल्यू को ढूँढने का प्रयत्न करती है (लिनियर, बाइनरी सर्च आदि)।" }, { "question": "एरे के मुकाबले लिंक्ड लिस्ट में खोज (Search) का समय जटिलता प्रायः क्या होगी?", "options": [ "O(1)", "O(n)", "O(n log n)", "O(log n)" ], "correct": 1, "explanation": "लिंक्ड लिस्ट में सामान्यतः एलिमेंट खोजने के लिए सूची के सभी नोड्स को क्रमवार जाँचना पड़ता है, इसीलिए O(n) है।" }, { "question": "स्टैक में ‘push’ ऑपरेशन क्या करता है?", "options": [ "स्टैक खाली करता है", "स्टैक से टॉप एलिमेंट निकालता है", "स्टैक के टॉप पर नया एलिमेंट जोड़ता है", "स्टैक को उल्टा करता है" ], "correct": 2, "explanation": "स्टैक में push, टॉप के ऊपर एक नया एलिमेंट डालने की क्रिया है; उसी तरह pop शीर्ष के एलिमेंट को हटाता है।" }, { "question": "बाइनरी ट्री (Binary Tree) में प्रत्येक नोड के पास अधिकतम कितने चाइल्ड हो सकते हैं?", "options": [ "3", "4", "2", "कोई सीमा नहीं" ], "correct": 2, "explanation": "बाइनरी ट्री के किसी भी नोड के पास अधिकतम 2 चाइल्ड (left, right) हो सकते हैं।" }, { "question": "ग्राफ में किसी दो वर्टिस के बीच एक से अधिक एज हो सकते हैं, तो उस ग्राफ को क्या कहते हैं?", "options": [ "मल्टीग्राफ (Multigraph)", "सरल ग्राफ", "दिशाहीन ग्राफ", "बाइपार्टाइट ग्राफ" ], "correct": 0, "explanation": "मल्टीग्राफ में दो वर्टिस के बीच एक से अधिक एज हो सकते हैं। साधारण (simple) ग्राफ में वर्टिस के बीच केवल एक एज की अनुमति होती है।" }, { "question": "हैशिंग में ‘कोलिजन (Collision)’ कब होता है?", "options": [ "जब दो भिन्न कुंजियाँ (keys) हैश फंक्शन से एक ही इंडेक्स को उत्पन्न कर दें", "ट्रांसवर्सल में देरी हो", "डाटा स्ट्रक्चर में कोई एरर हो", "केवल सिंगल लिनियर प्रोबिंग" ], "correct": 0, "explanation": "जब दो अलग-अलग keys हैश फंक्शन से वही इंडेक्स हासिल कर लें, उसे collision कहते हैं। इसे दूर करने हेतु अलग-अलग collision resolution तकनीकें अपनाई जाती हैं।" }, { "question": "‘बबल सॉर्ट (Bubble Sort)’ की औसत/बिग-ओ समय जटिलता क्या है?", "options": [ "O(n)", "O(n log n)", "O(n^2)", "O(log n)" ], "correct": 2, "explanation": "बबल सॉर्ट में हर पास में एलिमेंट्स की तुलना और स्वैपिंग होती है, इसके औसत और सबसे ख़राब केसेज़ में O(n^2) समय लगता है।" }, { "question": "‘बाइनरी सर्च (Binary Search)’ के लिए मुख्य शर्त क्या है?", "options": [ "लिंक्ड लिस्ट होना", "अनसॉर्टेड डेटा", "डेटा को सॉर्टेड (क्रमबद्ध) होना अनिवार्य", "डेटा बहुत बड़ा होना" ], "correct": 2, "explanation": "बाइनरी सर्च तभी सफलतापूर्वक लागू किया जा सकता है, जब एलिमेंट्स क्रमबद्ध (sorted) हों, क्योंकि ये मिड पॉइंट के आधार पर खोज को विभाजित करता है।" }, { "question": "लिंक्ड लिस्ट में डेटा जोड़ने की समय जटिलता (इन्सर्शन) अंत में (tail पर) करने के लिए आम तौर पर कितनी होती है (मान लें कि हमारे पास टेल पॉइंटर न हो)?", "options": [ "O(1)", "O(n)", "O(log n)", "O(n^2)" ], "correct": 1, "explanation": "अगर केवल हेड पॉइंटर है, तो अंत में नया नोड जोड़ने के लिए पहले हमें लिस्ट के अंतिम नोड तक पहुँचना होगा (O(n)), फिर जोड़ सकते हैं। टेल पॉइंटर हो तो O(1) में कर सकते हैं।" }, { "question": "डबल लिंक्ड लिस्ट (Doubly Linked List) में प्रत्येक नोड में कौन-सी जानकारी रहती है?", "options": [ "केवल डेटा", "डेटा, next और prev पॉइंटर", "सिर्फ अगला पॉइंटर", "keystore और valuestore" ], "correct": 1, "explanation": "डबल लिंक्ड लिस्ट में डेटा के अलावा दो पॉइंटर रहते हैं—एक अगले नोड के लिए (next), दूसरा पिछले नोड के लिए (prev)।" }, { "question": "स्टैक के व्यवहार का एक रोज़मर्रा का उदाहरण क्या हो सकता है?", "options": [ "लाइन में खड़े लोग", "डिशेज़ (plates) का ढेर जहां उपर वाली प्लेट पहले उठाई जाती है", "बस में बैठने वालों की कतार", "कॉलबैक लिस्ट" ], "correct": 1, "explanation": "प्लेट्स के ढेर में नई प्लेट टॉप पर जाती है और निकालते समय भी उपर वाली ही निकाली जाती है — यह स्टैक की LIFO संरचना का उदाहरण है।" }, { "question": "क्यू (Queue) के वास्तविक जीवन उदाहरण में कौन-सा फिट होगा?", "options": [ "प्लेट का ढेर", "कस्टमर लाइन – जहाँ सबसे आगे वाला कस्टमर पहले सर्व होता है", "बुक्स का स्टैक", "डिस्क ड्राइव" ], "correct": 1, "explanation": "बैंक या टिकट काउंटर पर कतार (queue) में सबसे पहले आने वाला व्यक्ति (जिसने सबसे पहले लाइन जॉइन की) सर्व किया जाता है, यानी FIFO।" }, { "question": "BST (Binary Search Tree) की विशेषता क्या है?", "options": [ "प्रत्येक नोड का लेफ्ट subtree में उससे छोटे मान, राइट subtree में उससे बड़े मान होते हैं", "ऑर्डर का कोई नियम नहीं", "सभी नोड्स में पॉइंटर नहीं", "केवल डुप्लिकेट वैल्यूज़" ], "correct": 0, "explanation": "BST में प्रत्येक नोड के बाएँ subtree में वे एलिमेंट होते हैं जो उस नोड से छोटे हैं, तथा दाईं ओर जो बड़े हैं; यह सर्च को त्वरित बनाता है।" }, { "question": "‘DFS (Depth First Search)’ और ‘BFS (Breadth First Search)’ किस डेटा संरचना पर प्रयुक्त होती हैं?", "options": [ "स्टैक पर", "क्यू पर", "ग्राफ/ट्री पर विभिन्न traversal के लिए", "कंप्यूटर के हार्डवेयर पर" ], "correct": 2, "explanation": "DFS और BFS ग्राफ या ट्री traversal के एल्गोरिदम हैं; DFS में स्टैक/रिकर्शन उपयोग होता है, BFS में क्यू उपयोग होता है, लेकिन दोनों का मुख्य उपयोग ग्राफ/ट्री को अन्वेषण (traverse) करने में है।" }, { "question": "हैशिंग में ओपन एड्रेसिंग (Open Addressing) की तकनीक क्या है?", "options": [ "हैश वैल्यू को Randomly चुनना", "कोलिजन होने पर एलिमेंट को किसी नई जगह (प्रोबिंग) खोजकर उसी टेबल में रखना", "सेपरेट चेनिंग करना", "डिस्क पर डेटा ले जाना" ], "correct": 1, "explanation": "ओपन एड्रेसिंग में जब कोलिजन होती है, तो हम दूसरी खाली लोकेशन (प्रोब) ढूँढते हैं (जैसे लिनियर प्रोबिंग, क्वाड्रेटिक प्रोबिंग, डबल हैशिंग) और एलिमेंट वही स्टोर करते हैं।" }, { "question": "क्विक सॉर्ट (Quick Sort) की औसत समय जटिलता क्या है?", "options": [ "O(n)", "O(n log n)", "O(n^2)", "O(log n)" ], "correct": 1, "explanation": "क्विक सॉर्ट की औसत जटिलता O(n log n) है, जबकि सबसे खराब स्थिति में यह O(n^2) हो सकती है (यदि पिवट चयन अनुचित हो)।" }, { "question": "बाइनरी सर्च का बिग-ओ समय जटिलता क्या है (सॉर्टेड एरे में)?", "options": [ "O(n)", "O(n^2)", "O(n log n)", "O(log n)" ], "correct": 3, "explanation": "बाइनरी सर्च प्रत्येक बार तलाश का दायरा आधा करता है, जिससे जाँच स्टेपों की संख्या log₂(n) के आस-पास होती है।" } // More questions as needed... ]; let currentQuestionIndex = 0; // Track current question let userAnswers = Array(quizData.length).fill(null); // Track user's answers // Timer variables let totalQuizTime = quizData.length * 30; // total seconds = 30 seconds * no. of questions let timeLeft = totalQuizTime; let timerInterval; // On page load, initialize quiz window.onload = function() { generateQuestionNav(); // Generate the question navigation circles loadQuestion(); startTimer(); // Start the countdown }; // Start the countdown timer function startTimer() { updateTimerDisplay(timeLeft); timerInterval = setInterval(() => { timeLeft--; updateTimerDisplay(timeLeft); if (timeLeft <= 0) { clearInterval(timerInterval); showResults(); // Force show results if time is up } }, 1000); } // Update timer on the screen in mm:ss format function updateTimerDisplay(seconds) { const timerEl = document.getElementById("timer"); const mins = Math.floor(seconds / 60).toString().padStart(2, '0'); const secs = (seconds % 60).toString().padStart(2, '0'); timerEl.innerText = `Time: ${mins}:${secs}`; } // Toggle the question nav when hamburger is pressed const hamburgerBtn = document.getElementById('hamburgerBtn'); hamburgerBtn.addEventListener('click', () => { document.getElementById('questionNavOverlay').classList.toggle('show'); }); // Close hamburger menu if user clicks outside the nav and menu document.addEventListener('click', (e) => { const navOverlay = document.getElementById('questionNavOverlay'); const hamburger = document.getElementById('hamburgerBtn'); // If the menu is open, and the click is outside both the overlay and the hamburger, close it if ( navOverlay.classList.contains('show') && !navOverlay.contains(e.target) && !hamburger.contains(e.target) ) { navOverlay.classList.remove('show'); } }); // Create small clickable circles for each question function generateQuestionNav() { const navContainer = document.getElementById("questionNav"); navContainer.innerHTML = ""; // clear old items if any quizData.forEach((_, index) => { const circle = document.createElement("div"); circle.classList.add("circle-number"); circle.innerText = index + 1; // Show question number (1-based) circle.onclick = () => jumpToQuestion(index); navContainer.appendChild(circle); }); } // Jump to a specific question function jumpToQuestion(qIndex) { currentQuestionIndex = qIndex; // Hide the nav on mobile after selection document.getElementById('questionNavOverlay').classList.remove('show'); // Reset submission/next button state document.getElementById("submitAnswerButton").classList.remove("hidden"); document.getElementById("nextButton").classList.add("hidden"); loadQuestion(); } // Load current question function loadQuestion() { highlightCurrentCircle(); // Hide explanation area and Next button initially document.getElementById("explanation").classList.add("hidden"); document.getElementById("nextButton").classList.add("hidden"); const questionData = quizData[currentQuestionIndex]; document.getElementById("question").innerText = questionData.question; document.getElementById("questionCounter").innerText = `${currentQuestionIndex + 1}/${quizData.length}`; // Clear old choices const choicesContainer = document.getElementById("choices"); choicesContainer.innerHTML = ""; // Populate choices questionData.options.forEach((option, index) => { const choiceElement = document.createElement("div"); choiceElement.className = "choice"; choiceElement.innerText = option; // If previously selected, mark it if (userAnswers[currentQuestionIndex] === index) { choiceElement.classList.add("selected"); } // On clicking a choice choiceElement.onclick = () => { // Clear all selections first document.querySelectorAll(".choice").forEach(c => c.classList.remove("selected")); // Mark this one as selected choiceElement.classList.add("selected"); userAnswers[currentQuestionIndex] = index; }; choicesContainer.appendChild(choiceElement); }); // Handle Previous button visibility document.getElementById("prevButton").style.display = currentQuestionIndex === 0 ? "none" : "inline-block"; } // Highlight the current question circle function highlightCurrentCircle() { const circles = document.querySelectorAll(".circle-number"); circles.forEach((circle, idx) => { circle.classList.remove("active"); if (idx === currentQuestionIndex) { circle.classList.add("active"); } }); } // Submit the current question's answer function submitAnswer() { const questionData = quizData[currentQuestionIndex]; const userAnswer = userAnswers[currentQuestionIndex]; // Show the explanation div const explanationDiv = document.getElementById("explanation"); explanationDiv.classList.remove("hidden"); // Clear previous correctness classes and disable further selection document.querySelectorAll(".choice").forEach((c) => { c.classList.add("disabled"); c.onclick = null; }); // Determine correctness or skipping if (userAnswer === null) { explanationDiv.innerHTML = "You Skipped the question.<br/><br/>व्याख्या: " + questionData.explanation; showPopupMessage("You Skipped the question", false); } else if (userAnswer === questionData.correct) { explanationDiv.innerHTML = "You got it right!<br/><br/>व्याख्या: " + questionData.explanation; showPopupMessage("You got it right", true); // Highlight correct choice document.querySelectorAll(".choice")[userAnswer].classList.add("correct"); } else { explanationDiv.innerHTML = "You got it wrong.<br/><br/>व्याख्या: " + questionData.explanation; showPopupMessage("You got it wrong", false); // Highlight correct choice document.querySelectorAll(".choice")[questionData.correct].classList.add("correct"); // Mark the chosen one as incorrect document.querySelectorAll(".choice")[userAnswer].classList.add("incorrect"); } // Hide the submit button, show the next button document.getElementById("submitAnswerButton").classList.add("hidden"); document.getElementById("nextButton").classList.remove("hidden"); } // Go to the next question or show final results function nextQuestion() { currentQuestionIndex++; if (currentQuestionIndex >= quizData.length) { // Show results if no more questions showResults(); } else { // Reset buttons document.getElementById("submitAnswerButton").classList.remove("hidden"); document.getElementById("nextButton").classList.add("hidden"); loadQuestion(); } } // Go to the previous question function previousQuestion() { if (currentQuestionIndex > 0) { currentQuestionIndex--; document.getElementById("submitAnswerButton").classList.remove("hidden"); document.getElementById("nextButton").classList.add("hidden"); loadQuestion(); } } // Show final quiz results function showResults() { // Stop the timer if it's still running clearInterval(timerInterval); // Calculate correct answers const correctAnswersCount = userAnswers.filter( (ans, i) => ans === quizData[i].correct ).length; // Hide quiz content document.getElementById("quizContent").classList.add("hidden"); // Show results document.getElementById("resultContent").classList.remove("hidden"); const percentage = (correctAnswersCount / quizData.length) * 100; let resultHTML = ""; if (percentage >= 60) { resultHTML = `<div class="congrats">🎉 बधाई हो! आपने ${percentage.toFixed( 2 )}% स्कोर किया है!</div>`; } else { resultHTML = `<div class="sad">😢 आपने ${percentage.toFixed( 2 )}% स्कोर किया है। अगली बार के लिए शुभकामनाएं!</div>`; } document.getElementById("resultMessage").innerHTML = resultHTML; document.getElementById("scoreMessage").innerText = `आपने कुल ${quizData.length} में से ${correctAnswersCount} प्रश्न सही उत्तर दिए हैं।`; } // Optional popup message function showPopupMessage(message, isCorrect) { const popup = document.getElementById('popupMessage'); popup.innerText = message; popup.className = ''; popup.classList.add('show'); popup.classList.add(isCorrect ? 'correct' : 'incorrect'); setTimeout(() => { popup.classList.remove('show'); popup.classList.add('hidden'); }, 2000); } // Button event listeners document.getElementById('prevButton').addEventListener('click', previousQuestion); document.getElementById('submitAnswerButton').addEventListener('click', submitAnswer); document.getElementById('nextButton').addEventListener('click', nextQuestion); // Predefined Darker Color Themes const themes = [ { header: '#a31645', headerText: '#ffffff', container: '#e8c4d6', containerText: '#6e0c36', headings: '#6e0c36' }, // Berry Delight { header: '#00574b', headerText: '#ffffff', container: '#b3dfd7', containerText: '#00382e', headings: '#00382e' }, // Ocean Breeze { header: '#c95a00', headerText: '#ffffff', container: '#dca865', containerText: '#7a3400', headings: '#7a3400' }, // Sunset Glow { header: '#4a0f6f', headerText: '#ffffff', container: '#cdb5e3', containerText: '#320b4a', headings: '#320b4a' }, // Calming Lavender { header: '#1e4d2b', headerText: '#ffffff', container: '#98c1a3', containerText: '#122417', headings: '#122417' }, // Forest Retreat { header: '#c99800', headerText: '#ffffff', container: '#e8d18a', containerText: '#6c4f00', headings: '#6c4f00' }, // Golden Elegance { header: '#01477e', headerText: '#ffffff', container: '#86b9e4', containerText: '#00223d', headings: '#00223d' }, // Sky Calm { header: '#5a3b2e', headerText: '#ffffff', container: '#b8a89c', containerText: '#32211a', headings: '#32211a' }, // Retro Rust { header: '#b34727', headerText: '#ffffff', container: '#f2c29d', containerText: '#6a2915', headings: '#6a2915' }, // Warm Peach { header: '#0f4c43', headerText: '#ffffff', container: '#92c3b8', containerText: '#072822', headings: '#072822' }, // Cool Mint ]; // Apply Random Darker Theme function applyRandomTheme() { const header = document.querySelector('.header'); const container = document.querySelector('.content-container'); const headings = document.querySelectorAll('.content-container h2'); // Select a random theme const randomTheme = themes[Math.floor(Math.random() * themes.length)]; // Apply Header Colors header.style.backgroundColor = randomTheme.header; header.style.color = randomTheme.headerText; // Apply Container Colors container.style.backgroundColor = randomTheme.container; container.style.color = randomTheme.containerText; // Apply Heading Colors headings.forEach((heading) => { heading.style.color = randomTheme.headings; heading.style.borderBottom = `2px solid ${randomTheme.headings}`; }); } // Apply the theme on page load window.onload = function () { applyRandomTheme(); // Set random theme generateQuestionNav(); // Generate question navigation loadQuestion(); // Load the first question startTimer(); // Start the countdown timer }; </script> </body> </html> <!-- /wp:html -->