← Back to HTML Course | Chapter 10: Reference & Interview Prep | Lesson 19 of 20

HTML क्विज़

फ़र्ज़ करें आप किसी लंबे chapter summary को पढ़कर किसी test की तैयारी कर रहे हैं। आपने सभी facts पढ़ लिए, लेकिन आपको नहीं पता कि आप material असल में समझे भी हैं या नहीं। अपने knowledge को test करने के लिए, आप एक quick interactive quiz देते हैं। HTML quiz वही interactive test है। form elements (जैसे radio buttons, checkboxes, और buttons) को simple scripts के साथ जोड़कर, आप सीधे अपने page पर responsive questionnaires बना सकते हैं। आप इनका इस्तेमाल अपने students को test करने, user feedback इकट्ठा करने, या तुरंत answers grade करने वाले interactive quizzes बनाने के लिए कर सकते हैं।

स्ट्रक्चरल क्विज़ सेटअप

एक HTML quiz बनाने के लिए, आप अपने सभी questions, selection fields, और submission buttons को साफ-सुथरे तरीके से एक साथ group करने के लिए अपने page पर एक standard form container define करते हैं।

Note: अपने quiz को structured और submit करने में आसान बनाए रखने के लिए हमेशा questions को एक form container के अंदर group करें।
Warning: quiz inputs को form container के बाहर रखने से data सही तरीके से package और submit नहीं हो पाएगा।

उदाहरण: Structural Quiz Setup

markup
<form action="/submit-quiz" method="post">
</form>

सिंगल-चॉइस क्वेश्चन्स

single-choice questions के लिए, आप grouped radio buttons इस्तेमाल करते हैं। अपने सभी radio button inputs को एक ही name attribute देकर, आप सुनिश्चित करते हैं कि users सिर्फ एक ही answer चुन सकें।

Note: answers पर क्लिक करना काफी आसान बनाने के लिए अपने radio button inputs को descriptive label tags से लिंक करें।
Warning: अगर आप अपने radio buttons को एक जैसा name देना भूल जाते हैं, तो users कई options select कर पाएंगे, जिससे इसका मकसद ही खत्म हो जाता है।

उदाहरण: Single-Choice Questions

markup
<input type="radio" name="q1" value="a"> Paris
<input type="radio" name="q1" value="b"> London

मल्टी-चॉइस क्वेश्चन्स

उन multi-choice questions के लिए जहाँ users एक से ज़्यादा सही answer चुन सकते हैं, आप checkboxes इस्तेमाल करते हैं। हर checkbox स्वतंत्र रूप से काम करता है, जिससे users एक साथ कई selections toggle कर सकते हैं।

Note: ऐसे complex topics पर users को test करने के लिए checkbox questions इस्तेमाल करें जिनमें कई सही factors हों।
Warning: options समझाने के लिए अपने checkboxes के बगल में हमेशा साफ, मददगार labels लिखें।

उदाहरण: Multi-Choice Questions

markup
<input type="checkbox" name="q2" value="a"> HTML
<input type="checkbox" name="q2" value="b"> CSS

टेक्स्ट और लिखित उत्तर

आप अपने quizzes में standard text inputs या textareas इस्तेमाल करके लिखित questions भी शामिल कर सकते हैं। ये custom definitions, keywords, या short essays पर users को test करने के लिए बिल्कुल सही हैं।

Note: users को formatting examples दिखाने के लिए अपने text inputs के अंदर placeholder hints इस्तेमाल करें।
Warning: case sensitivity और spelling variations की वजह से written answers को simple scripts से अपने आप grade करना ज़्यादा मुश्किल होता है।

उदाहरण: Text and Written Answers

markup
<label for="q3">Define HTML:</label>
<textarea id="q3" name="q3"></textarea>

JavaScript से क्विज़ ग्रेड करना

अपने quiz को interactive बनाने के लिए, आप एक JavaScript function लिखते हैं जो user के form submit करने पर चलता है।

यह script default page reload को रोकता है, सभी selected input values capture करता है, उन्हें सही answers से चेक करता है, और तुरंत final score दिखाता है।

Note: browser को page reload करने से रोकने के लिए अपने submission script के अंदर preventDefault method इस्तेमाल करें।
Warning: user progress को सुरक्षित रखने के लिए हमेशा अपने cloned data arrays पर ही calculations करें।

उदाहरण: Grading Quizzes with JavaScript

markup
<form onsubmit="event.preventDefault(); console.log('Score calculated')">
  <input type="radio" name="q1" value="a"> Answer A
  <button type="submit">Submit Quiz</button>
</form>
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.