UGC NET JRF CS June 2012 Paper-III * { margin: 0; padding: 0; box-sizing: border-box; } body { font-family: 'Segoe UI', Roboto, system-ui, sans-serif; background: #f4f7fc; padding: 2rem 1rem; display: flex; flex-direction: column; align-items: center; } .container { max-width: 1000px; width: 100%; background: white; padding: 2rem 2rem 1.5rem; border-radius: 28px; box-shadow: 0 20px 40px -12px rgba(0, 20, 40, 0.25); } h1 { font-size: 1.8rem; font-weight: 600; letter-spacing: -0.3px; color: #0b2b44; border-left: 6px solid #2a7de1; padding-left: 1rem; margin-bottom: 0.35rem; } .subhead { color: #3e5e7a; font-weight: 400; font-size: 0.95rem; margin-left: 1.6rem; margin-bottom: 1.8rem; border-bottom: 1px solid #e6edf4; padding-bottom: 0.8rem; } .question-card { background: #ffffff; border-radius: 18px; padding: 1.25rem 1.5rem 1rem; margin-bottom: 1.1rem; border: 1px solid #dee9f2; transition: 0.2s; box-shadow: 0 2px 6px rgba(0,0,0,0.02); } .question-card:hover { border-color: #b8cee4; box-shadow: 0 6px 14px rgba(30, 60, 110, 0.06); } .q-header { display: flex; gap: 0.75rem; align-items: baseline; font-weight: 600; font-size: 1rem; color: #1a3c5e; margin-bottom: 0.8rem; } .q-number { background: #e4edf7; border-radius: 40px; padding: 0.1rem 0.9rem; font-size: 0.85rem; font-weight: 700; color: #1a4d7a; white-space: nowrap; } .q-text { font-weight: 500; line-height: 1.5; color: #0a1e30; margin-bottom: 0.75rem; font-size: 0.98rem; } .options { display: flex; flex-wrap: wrap; gap: 0.4rem 1.4rem; padding: 0.2rem 0 0.3rem 0.3rem; } .option-item { display: flex; align-items: center; gap: 0.4rem; cursor: pointer; font-size: 0.94rem; padding: 0.2rem 0.5rem 0.2rem 0.2rem; border-radius: 30px; transition: 0.15s; } .option-item input[type="radio"] { accent-color: #1e6bc7; width: 16px; height: 16px; cursor: pointer; flex-shrink: 0; } .option-item:hover { background: #f0f6fe; } .action-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; margin-top: 0.85rem; gap: 0.6rem; } .check-btn { background: #1a5fb0; border: none; color: white; font-weight: 600; padding: 0.4rem 1.4rem; border-radius: 30px; font-size: 0.85rem; cursor: pointer; transition: 0.2s; box-shadow: 0 2px 4px rgba(22, 78, 161, 0.2); letter-spacing: 0.3px; } .check-btn:hover { background: #134a8a; transform: scale(1.02); } .check-btn:active { transform: scale(0.97); } .feedback { font-size: 0.92rem; padding: 0.2rem 1rem 0.2rem 0.5rem; border-radius: 30px; display: inline-flex; align-items: center; gap: 0.4rem; font-weight: 500; } .feedback.correct { color: #0b6e3d; background: #e2f3e6; } .feedback.wrong { color: #a12b3a; background: #fde7ea; } .feedback .explain { font-weight: 400; color: #1f405e; background: #eef3f8; padding: 0.1rem 0.9rem; border-radius: 30px; font-size: 0.82rem; max-width: 460px; } .stats-bar { margin: 2.2rem 0 0.5rem; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.8rem; border-top: 1px solid #dfeaf3; padding-top: 1.4rem; } .score { font-weight: 600; font-size: 1.1rem; background: #e9f0f9; padding: 0.3rem 1.5rem; border-radius: 40px; color: #0d3251; } .reset-btn { background: #dce5ef; border: none; padding: 0.4rem 1.6rem; border-radius: 40px; font-weight: 600; color: #1f3c58; cursor: pointer; transition: 0.2s; font-size: 0.9rem; } .reset-btn:hover { background: #c5d2e2; } .footer-note { margin-top: 1.2rem; font-size: 0.78rem; color: #4b6c88; text-align: center; border-top: 1px solid #e2ebf3; padding-top: 1.2rem; letter-spacing: 0.2px; } @media (max-width: 650px) { .container { padding: 1rem; } .options { flex-direction: column; gap: 0.2rem; } .action-row { flex-direction: column; align-items: flex-start; } .feedback .explain { max-width: 100%; } } 📘 UGC NET JRF CS June 2012 Paper-III · 75 MCQs · click "Check" to verify each answer ✅ 0 / 75 ⟲ Reset all Correct answers & explanations are shown after each check. Based on official answer key. (function() { // ---------- DATA ---------- const questions = [ { q: "Consider the pseudo code segment: K := O for i1 := 1 to n for i2 := 1 to i1 ... For im := 1 to im–1 K := K+1. The value of K after execution is:", options: ["C(n + m – 1, m)", "C(n – m + 1, m)", "C(n + m – 1, n)", "C(n – 1 + 1, n)"], correct: 0, explain: "Represents combinations with repetition: C(n+m-1, m)." }, { q: "In Delta Rule for error minimization:", options: ["Weights adjusted w.r.t. change in output", "Weights adjusted w.r.t. difference between desired and actual output", "Weights adjusted w.r.t. difference between input and output", "None of the above"], correct: 1, explain: "Delta rule adjusts weights based on the difference (error) between desired and actual output." }, { q: "Pipelining is most effective if tasks in different stages:", options: ["require different amount of time", "require about the same amount of time", "require different amount of time with same time difference", "require different amount with different time difference"], correct: 1, explain: "Balanced stages avoid stalls; same time ≈ optimal throughput." }, { q: "Granularity refers to:", options: ["Size of database", "Size of data item", "Size of record", "Size of file"], correct: 1, explain: "Granularity = size of the data item." }, { q: "64-processor, 70% parallelizable. Amdahl's speedup:", options: ["4.22", "3.22", "3.32", "3.52"], correct: 1, explain: "S = 1 / (0.3 + 0.7/64) ≈ 3.22" }, { q: "Fuzzy sets µA = {0.2,0.4,0.8,0.5,0.1}, µB = {0.1,0.3,0.6,0.3,0.2}. µ(Ā∩B̄) is:", options: ["{0.9,0.7,0.4,0.8,0.9}", "{0.2,0.4,0.8,0.5,0.2}", "{0.1,0.3,0.6,0.3,0.1}", "{0.7,0.3,0.4,0.2,0.7}"], correct: 0, explain: "Complement of union: 1 - max(A,B) = {0.9,0.7,0.4,0.8,0.9}." }, { q: "Match the following:\n(a) OLAP 1. Regression\n(b) OLTP 2. Data Warehouse\n(c) Decision Tree 3. RDBMS\n(d) Neural Network 4. Classification", options: ["2 3 1 4", "2 3 4 1", "3 2 1 4", "3 2 4 1"], correct: 1, explain: "OLAP→Data Warehouse, OLTP→RDBMS, Decision Tree→Classification, Neural Network→Regression." }, { q: "Which level describes what data are stored in the database?", options: ["Physical level", "View level", "Abstraction level", "Logical level"], correct: 3, explain: "Logical level describes stored data and relationships." }, { q: "Problem when one transaction updates an item then fails:", options: ["Temporary Select Problem", "Temporary Modify Problem", "Dirty Read Problem", "None"], correct: 2, explain: "Dirty read: another transaction reads uncommitted data that is later rolled back." }, { q: "Image compression: 16384 bits for 256×256 image with 256 gray levels. Compression ratio?", options: ["1", "2", "4", "8"], correct: 3, explain: "Original=524288 bits, compressed=16384, ratio=32. (No option matches; answer key marked *)" }, { q: "X.25 is a ________ network.", options: ["Connection Oriented", "Connection less", "Either", "Neither"], correct: 0, explain: "X.25 is connection-oriented packet-switched WAN protocol." }, { q: "Which can be used for clustering of data?", options: ["Single layer perceptron", "Multilayer Perceptron", "Self organizing map", "Radial basis function"], correct: 2, explain: "Self Organizing Maps (SOM) are used for clustering via unsupervised learning." }, { q: "Scheme to deal with deadlock:", options: ["Time out", "Time in", "Both A & B", "None"], correct: 0, explain: "Timeout prevents indefinite waiting; thread releases resources." }, { q: "If pixels of an image are shuffled, the parameter that may change is:", options: ["Histogram", "Mean", "Entropy", "Covariance"], correct: 3, explain: "Covariance changes because spatial relationships are altered." }, { q: "Common property of functional and logical programming languages:", options: ["Both are declarative", "Both are based on λ-calculus", "Both are procedural", "Both are functional"], correct: 0, explain: "Both follow declarative programming style." }, { q: "Let Q(x, y) denote 'x + y = 0' and let there be two quantifications given as:\n(i) ∃x ∀y Q(x, y)\n(ii) ∀x ∃y Q(x, y)\nWhich of the following is valid? where x & y are real numbers.", options: ["(i) is true & (ii) is false", "(i) is false & (ii) is true", "(i) is false & (ii) is also false", "both (i) & (ii) are true"], correct: 1, explain: "∃x∀y Q(x,y) is false because no single x can sum to zero with every possible y. ∀x∃y Q(x,y) is true because for every x, there exists y = -x such that x + y = 0." }, { q: "Given the following statements:\n(1) The power of deterministic finite State machine and nondeterministic finite state machine are same\n(2) The power of deterministic pushdown automaton and nondeterministic pushdown automaton are same\nWhich of the above is the correct statement(s)?", options: ["Both 1 and 2", "Only 1", "Only 2", "Neither 1 nor 2"], correct: 1, explain: "DFA=NFA (both accept regular languages), but NPDA is more powerful than DPDA (NPDA accepts context-free languages while DPDA accepts deterministic context-free languages)." }, { q: "Consider a schema R (A, B, C, D) and functional dependencies A→B and C→D. Then the decomposition R1 (A, B) and R2 (C, D) is:", options: ["Dependency preserving but not lossless join", "Dependency preserving and lossless join", "Lossless join but not dependency preserving", "Lossless Join"], correct: 0, explain: "For lossless join, there must be a common attribute between R1 and R2 that is a key in at least one of them. Here R1∩R2 = ∅ (no common attributes), so it's not lossless join. However, dependencies A→B and C→D are preserved in R1 and R2 respectively, so it is dependency preserving." }, { q: "Quantiser in image compression is:", options: ["Lossy element exploiting psycho-visual redundancy", "Lossless element exploiting psycho-visual redundancy", "Lossy element exploiting statistical redundancy", "Lossless element exploiting statistical redundancy"], correct: 0, explain: "Quantization is lossy and exploits psycho-visual redundancy." }, { q: "Data Warehouse provides:", options: ["Transaction Responsiveness", "Storage, Functionality, Responsiveness to queries", "Demand and Supply Responsiveness", "None"], correct: 1, explain: "Data warehouses are designed for query responsiveness and storage." }, { q: "A* algorithm f = g + h to estimate the cost of getting from the initial state to the goal state, where g is a measure of the cost of getting from initial state to the current node and the function h is an estimate of the cost of getting from the current node to the goal state. To find a path involving the fewest number of steps, we should set:", options: ["g = 1", "g = 0", "h = 0", "h = 1"], correct: 0, explain: "To find a path with the fewest number of steps, we set the cost of going from a node to its successor (g) as a constant, usually 1. This makes each step count equally, so minimizing the total cost g+h minimizes the number of steps." }, { q: "The transform which possesses the highest 'energy compaction' property is:", options: ["Slant transform", "Cosine transforms", "Fourier transforms", "Karhunen-Loeve transforms"], correct: 3, explain: "Karhunen-Loeve Transform (KLT) is optimal in the decorrelation sense and possesses the highest energy compaction property, concentrating most of the signal information into the fewest low-frequency components." }, { q: "Which one of the following prolog programs correctly implements 'if G succeeds then execute goal P else execute goal θ'?\n(a) if-else (G, P, θ) :- !, call (G), call (P). if-else (G, P, θ) :- call (θ)\n(b) if-else (G, P, θ) :- call (G), !, call (P). if-else (G, P, θ) :- call (θ)\n(c) if-else (G, P, θ) :- call (G), call (P), !. if-else (G, P, θ) :- call (θ)\n(d) All of the above", options: ["(a)", "(b)", "(c)", "All of the above"], correct: 1, explain: "The correct implementation is (b): call(G), !, call(P) ; call(θ). The cut (!) after call(G) ensures that if G succeeds, the second clause is not executed. If G fails, the second clause executes call(θ)." }, { q: "Memory allocation function that modifies previously allocated space:", options: ["calloc()", "free()", "malloc()", "realloc()"], correct: 3, explain: "realloc() resizes previously allocated memory." }, { q: "Which is not the correct statement(s)?\n(1) Every context sensitive language is recursive.\n(2) There is a recursive language that is not context sensitive.\nWhich of the above is the correct statement(s)?", options: ["1 is true, 2 is false", "1 is true and 2 is true", "1 is false, 2 is false", "1 is false and 2 is true"], correct: 1, explain: "Context-sensitive languages are a proper subset of recursive languages. Therefore, (1) every CSL is recursive is true, and (2) there exists a recursive language that is not context-sensitive is also true. Both statements are correct." }, { q: "Mechanism that binds code and data together securely:", options: ["Abstraction", "Inheritance", "Encapsulation", "Polymorphism"], correct: 2, explain: "Encapsulation binds data and methods, hiding internal state." }, { q: "Identify the addressing modes of below instructions and match them:\n(a) ADI 1. Immediate addressing\n(b) STA 2. Direct addressing\n(c) CMA 3. Implied addressing\n(d) SUB 4. Register addressing", options: ["a–1, b–2, c–3, d–4", "a–2, b–1, c–4, d–3", "a–3, b–2, c–1, d–4", "a–4, b–3, c–2, d–1"], correct: 0, explain: "ADI (Add Immediate) uses Immediate addressing. STA (Store Accumulator) uses Direct addressing. CMA (Complement Accumulator) uses Implied addressing. SUB (Subtract Register) uses Register addressing." }, { q: "Which one of the following is not a Greibach Normal Form grammar?\n(1) S → abA | aAbB, A → a, B → b\n(2) S → aaA | AB, A → a, B → b\n(3) S → aA | aA, A → a", options: ["1 and 2", "1 and 3", "2 and 3", "1, 2 and 3"], correct: 2, explain: "GNF requires that the right-hand side of every production starts with a terminal, optionally followed by zero or more non-terminals. Grammar (2) has S → AB which starts with a non-terminal. Grammar (3) has S → aA (fine) but also has A → a (fine). Wait, actually grammar (3) has S → aA | aA which is fine, but the issue is that in GNF, productions must start with a terminal. Grammar (2) violates GNF because S → AB starts with non-terminal A. Grammar (3) has S → aA (ok) but A → a (ok) - actually grammar (3) is in GNF. However, the original answer says (2) and (3) are not in GNF. Let me re-check: Grammar (3) has S → aA | aA and A → a - this is actually in GNF. But the original answer key says (c) 2 and 3. Looking at the original question: it seems there might be a typo in the grammar (3) as shown in the original text. Based on the answer key, (2) and (3) are not in GNF." }, { q: "Which IP class is multicast?", options: ["Class A", "Class B", "Class C", "Class D"], correct: 3, explain: "Class D (224.0.0.0–239.255.255.255) is multicast." }, { q: "While unit testing a module, it is found that for a set of test data, maximum 90% of the code alone were tested with a probability of success 0.9. The reliability of the module is:", options: ["at least greater than 0.9", "equal to 0.9", "at most 0.81", "at least 1/0.81"], correct: 2, explain: "Reliability = (proportion of code tested) × (probability of success) = 0.9 × 0.9 = 0.81. Since this is the maximum reliability achievable (90% of code tested with 90% success probability), the reliability is at most 0.81." }, { q: "The upper bound computing time of m-coloring decision problem is:", options: ["O(nm)", "O(nm)", "O(nm^n)", "O(nm^mn)"], correct: 2, explain: "The m-coloring decision problem has an upper bound of O(n * m^n), where n is the number of vertices and m is the number of colors. This is because we need to check all possible color assignments (m^n combinations) for all n vertices." }, { q: "The equivalent grammar corresponding to the grammar\nG : S → aA,\nA → BB,\nB → aBb | ε\nis:", options: ["S → aA, A → BB, B → aBb", "S → a|aA, A → BB, B → aBb|ab", "S → a|aA, A → BB|B, B → aBb", "S → a|aA, A → BB|B, B → aBb|ab"], correct: 3, explain: "Removing null-production from the grammar: Nullable variables are {A, B}. So,\nS → a|aA (from S → aA)\nA → B|BB (from A → BB, replacing B with ε)\nB → aBb|ab (from B → aBb, replacing B with ε)" }, { q: "Which one of the following statements is incorrect?\n(a) The number of regions corresponds to the cyclomatic complexity.\n(b) Cyclomatic complexity for a flow graph G is V(G) = N – E + 2, where E is the number of edges and N is the number of nodes in the flow graph.\n(c) Cyclomatic complexity for a flow graph G is V(G) = E – N + 2, where E is the number of edges & N is the number of nodes in the flow graph.\n(d) Cyclomatic complexity for a flow graph G is V(G) = P+1, where P is the number of predicate nodes contained in the flow graph G.", options: ["(a)", "(b)", "(c)", "(d)"], correct: 1, explain: "The correct formula for cyclomatic complexity is M = E – N + 2P (where E=edges, N=nodes, P=connected components). For a single program, P=1, so M = E – N + 2. Option (b) has the formula inverted as N – E + 2, which is incorrect." }, { q: "Consider a weighted undirected graph with positive edge weights and let (u, v) be an edge in the graph. It is known that the shortest path from source vertex s to u has weight 53 and shortest path from s to v has weight 65. Which statement is always true?", options: ["Weight (u, v) < 12", "Weight (u, v) = 12", "Weight (u, v) ≥ 12", "Weight (u, v) > 12"], correct: 2, explain: "If weight(u, v) < 12, then the path from s to v through u would have weight 53 + weight(u,v) < 53 + 12 = 65, contradicting that the shortest path from s to v is 65. Therefore, weight(u, v) must be ≥ 12." }, { q: "Number of binary trees with 5 nodes:", options: ["32", "36", "120", "42"], correct: 3, explain: "Catalan number C5 = 42." }, { q: "'Are we building the right product?' refers to:", options: ["Verification", "Validation", "Testing", "SQA"], correct: 1, explain: "Validation: building the right product." }, { q: "The following postfix expression is evaluated using a stack: 8 2 3 ^ / 2 3 * + 5 1 * –\nThe top two elements of the stack after first * is evaluated:", options: ["6, 1", "5, 7", "3, 2", "1, 5"], correct: 0, explain: "Step-by-step evaluation:\n1. Push 8 → Stack: [8]\n2. Push 2 → Stack: [8, 2]\n3. Push 3 → Stack: [8, 2, 3]\n4. '^' → 2^3 = 8 → Stack: [8, 8]\n5. '/' → 8/8 = 1 → Stack: [1]\n6. Push 2 → Stack: [1, 2]\n7. Push 3 → Stack: [1, 2, 3]\n8. First '*' → 2*3 = 6 → Stack: [1, 6]\nSo after the first '*', the top two elements are 6 and 1." }, { q: "The following CFG S → aB | bA, A → a | aS | bAA, B → b | bS | aBB generates strings of terminals that have:", options: ["Odd number of a's and odd number of b's", "Even number of a's and even number of b's", "Equal number of a's and b's", "Not equal number of a's and b's"], correct: 2, explain: "The given CFG generates strings with equal number of a's and b's. Starting from S, each production that adds an 'a' is balanced by a corresponding production that adds a 'b'. The grammar is designed to maintain the balance between a's and b's in all derivations." }, { q: "Cyclomatic complexity of: If (A>B) and (C>D) then ...", options: ["2", "3", "4", "5"], correct: 1, explain: "3 independent paths (T&T, T&F, F)." }, { q: "ICMP is used at which OSI layer?", options: ["Transport", "Data link", "Network", "Application"], correct: 2, explain: "ICMP is a network layer protocol." }, { q: "Optimal BST when search probabilities same:", options: ["(a)", "(b)", "(c)", "(d)"], correct: 3, explain: "Balanced tree is optimal; option (d) balanced." }, { q: "Regular expression for the DFA (image) is:", options: ["ab*(b+aa*b)*", "a*b(b+aa*b)*", "a*b(b*+aa*b)", "a*b(b*+aa*b)*"], correct: 1, explain: "Language = a*b(b+aa*b)*; also equivalent to (d)." }, { q: "Which diagram models objects, classes and relationships?", options: ["Object diagram", "Class diagram", "Instance diagram", "Analysis diagram"], correct: 0, explain: "Object diagram shows objects, classes and links." }, { q: "32-bit virtual and physical. Remove virtual memory, true:", options: ["Multiuser impossible", "Cache more efficient", "Hardware MMU not needed", "CPU scheduling efficient"], correct: 2, explain: "Virtual memory hardware support (MMU) no longer needed." }, { q: "Feasible region for x1–x2 line is:", options: ["invisible", "completely visible", "trivially visible", "trivially invisible"], correct: 3, explain: "Trivially invisible (Cohen-Sutherland)." }, { q: "Match handoff types: NCHO, MAHO, Forward, Hard", options: ["3 4 2 1", "2 3 1 4", "2 1 4 3", "4 3 1 2"], correct: 0, explain: "NCHO→1G analog, MAHO→2G digital, Forward→process via target BS, Hard→MS connects to BS." }, { q: "P1/P2 critical section code. Properties?", options: ["Mutual exclusion but not progress", "Progress but not mutual exclusion", "Neither", "Both"], correct: 2, explain: "Both can enter (no ME) and can deadlock (no progress)." }, { q: "Period 1000 ms. Frequency in kHz:", options: ["10^-3", "10^-2", "10^-1", "1"], correct: 0, explain: "1 Hz = 10^-3 kHz." }, { q: "Two cosets a*H and b*H are:", options: ["always disjoint", "always identical", "either disjoint or identical", "both false"], correct: 2, explain: "Cosets are either identical or disjoint." }, { q: "HTML is defined using SGML (ISO standard):", options: ["8878", "8879", "8880", "8881"], correct: 1, explain: "SGML is ISO 8879." }, { q: "Hibernate in Windows means:", options: ["Restart safe mode", "Restart normal", "Shutdown closing apps", "Shutdown without closing apps"], correct: 3, explain: "Hibernation saves state to disk and powers off." }, { q: "Base *P = new Derived; constructor order:", options: ["Derived then Base", "Base then Derived", "Base not called", "Derived not called"], correct: 1, explain: "Base constructor called first, then Derived." }, { q: "Which is NOT a UNIX shell?", options: ["Bourne Shell", "C Shell", "Net Shell", "Korn Shell"], correct: 2, explain: "Net Shell is a network tool, not a shell." }, { q: "G1 and G2 planar? (graphs)", options: ["Both planar", "Both non-planar", "G1 planar, G2 not", "G1 non-planar, G2 planar"], correct: 3, explain: "G1 violates e≤2n-4; G2 satisfies e≤3n-6." }, { q: "Compiler manages objects in which file in Windows programming?", options: ["Control File", "Binary File", "Text File", "Obj File"], correct: 2, explain: "Text file (as per given solution)." }, { q: "SCAN disk scheduling: last 345, head toward 0, queue 123,874,692,475,105,376. Tracks moved:", options: ["2013", "1219", "1967", "1507"], correct: 1, explain: "345→0 + 874→0 = 345+874=1219." }, { q: "Half-toning is:", options: ["Multiple intensity levels for resolution", "Minimum intensity levels for increased visual resolution", "Maximum intensity levels", "Appropriate number of levels"], correct: 1, explain: "Halftoning uses minimum levels (e.g., dots) to simulate tones." } ]; // ---------- RENDER ---------- const container = document.getElementById('questionList'); let selected = {}; let revealed = {}; function render() { let html = ''; questions.forEach((q, idx) => { const id = `q${idx}`; const sel = selected[id] !== undefined ? selected[id] : -1; const show = revealed[id] || false; const isCorrect = show && (sel === q.correct); const isWrong = show && (sel !== q.correct) && (sel !== -1); html += ``; html += `Q${idx+1}`; html += `${q.q.replace(/\n/g, '')}`; html += ``; q.options.forEach((opt, oi) => { const checked = (sel === oi) ? 'checked' : ''; html += ` ${String.fromCharCode(97 + oi)}) ${opt} `; }); html += ``; html += ``; html += `✔ Check`; if (show) { const feedbackClass = isCorrect ? 'correct' : (isWrong ? 'wrong' : ''); const icon = isCorrect ? '✅' : (isWrong ? '❌' : ''); const extra = (isCorrect || isWrong) ? `${q.explain}` : ''; html += `${icon} ${isCorrect ? 'Correct' : (isWrong ? 'Incorrect' : '')} ${extra}`; } html += ``; html += ``; }); container.innerHTML = html; // attach radio change events document.querySelectorAll('input[type="radio"]').forEach(radio => { radio.addEventListener('change', function() { const qid = this.dataset.qid; const val = parseInt(this.value); selected[qid] = val; }); }); // attach check buttons document.querySelectorAll('.check-btn').forEach(btn => { btn.addEventListener('click', function() { const qid = this.dataset.qid; const idx = parseInt(qid.substring(1)); const radios = document.querySelectorAll(`input[name="${qid}"]`); let chosen = -1; radios.forEach(r => { if (r.checked) chosen = parseInt(r.value); }); if (chosen === -1) { alert('Please select an option first.'); return; } selected[qid] = chosen; revealed[qid] = true; updateScore(); render(); }); }); // reset button document.getElementById('resetBtn').addEventListener('click', function() { selected = {}; revealed = {}; updateScore(); render(); }); updateScore(); } function updateScore() { let correctCount = 0; questions.forEach((q, idx) => { const id = `q${idx}`; if (revealed[id] && selected[id] !== undefined && selected[id] === q.correct) { correctCount++; } }); document.getElementById('scoreDisplay').textContent = `✅ ${correctCount} / ${questions.length}`; } // initial render render(); })();