-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexam.html
More file actions
337 lines (317 loc) · 15.7 KB
/
Copy pathexam.html
File metadata and controls
337 lines (317 loc) · 15.7 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="description" content="Exam Simulation — 40 questions, 60 minutes, 75% pass threshold. Weighted sampling integration in progress — see README.">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Exam Simulation — LPI 010-160</title>
<link rel="icon" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><text y='.9em' font-size='90'>🐧</text></svg>">
<link rel="stylesheet" href="style.css">
</head>
<body>
<a class="skip-link" href="#main-content">Skip to main content</a>
<div id="shell" tabindex="-1"><a id="main-content"></a>
<div class="topbar">
<a href="index.html" class="topbar-logo" aria-label="Go to Home">🐧 LPI <span>010-160</span></a>
<nav class="topbar-nav">
<a href="index.html">Home</a>
<a href="study.html">Study</a>
<a href="exam.html" class="active" aria-current="page">Exam</a>
<a href="drill.html">Drill</a>
<a href="weak.html">Hard</a>
<!-- Maps: held back, see docs/MAPS-PENDING.md -->
</nav>
</div>
<!-- Tab description banner -->
<div class="tab-desc">
⏱ <strong>Exam Simulation</strong> — Practice run under real exam conditions: 40 questions, 60 minutes, 75% to pass. No feedback until submission. Includes MCQ, multi-select, and fill-in question types.
</div>
<div id="startScreen">
<div class="card mb16" style="font-size:14px;line-height:1.8">
<table style="border-collapse:collapse;width:100%">
<tr><td style="color:var(--sub);width:130px">Questions</td><td><strong>40</strong> (8 per topic — weighted sampling pending)</td></tr>
<tr><td style="color:var(--sub)">Time</td><td><strong>60 minutes</strong> <span id="timerNote" class="muted small"></span></td></tr>
<tr><td style="color:var(--sub)">Pass threshold</td><td><strong>75%</strong> (30/40)</td></tr>
<tr><td style="color:var(--sub)">Navigation</td><td>← → freely · skip and return</td></tr>
<tr><td style="color:var(--sub)">Types</td><td>MCQ · ☑ Multi-select · ✏ Fill-in-blank</td></tr>
<tr><td style="color:var(--sub)">Feedback</td><td>Only shown <strong>after</strong> submission</td></tr>
</table>
</div>
<div class="btn-row">
<button class="btn accent lg" onclick="startExam()">▶ Start Exam</button>
<a href="index.html" class="btn outline">← Back</a>
</div>
</div>
<div id="examSession" style="display:none">
<div id="examBar">
<div class="timer" id="timer" aria-live="off" aria-label="Time remaining">60:00</div>
<button id="pauseBtn" onclick="togglePause()" style="display:none;padding:5px 12px;border-radius:6px;border:1.5px solid var(--border);background:var(--card);cursor:pointer;font-size:13px" aria-label="Pause timer">⏸</button>
<div style="flex:1">
<div class="progress-wrap"><div class="progress-fill" id="examProg"></div></div>
<div style="font-size:11px;color:var(--sub);margin-top:3px" id="examMeta" aria-live="polite"></div>
</div>
<button class="btn outline sm" onclick="confirmSubmit()">Submit</button>
</div>
<div id="examQArea" role="main"></div>
<div class="nav-bar">
<button class="btn outline" id="prevBtn" onclick="examNav(-1)" disabled>← Prev</button>
<div class="spacer"></div>
<span class="nav-info" id="examNavInfo" aria-live="polite"></span>
<div class="spacer"></div>
<button class="btn" id="nextBtn" onclick="examNav(1)">Next →</button>
</div>
<div class="mt16">
<div class="section-hd mb8">Question map <span class="muted" style="font-weight:400">(jump to any Q · ☑=multi · ✏=fill)</span></div>
<div id="qMap" style="display:flex;flex-wrap:wrap;gap:5px" role="navigation" aria-label="Question map"></div>
</div>
</div>
<div id="resultsScreen" style="display:none"></div>
</div>
<script src="config/exam.js"></script>
<script src="data/questions.js"></script>
<script src="data/questions.personal.js"></script>
<script src="assets/js/core.js"></script>
<script src="a11y.js"></script>
<script>
let examQs=[],examAnswers=[],examIdx=0,timerInterval=null,secondsLeft=3600,paused=false;
let examMultiSel={};
window.addEventListener('DOMContentLoaded',()=>{
const tm=a11yTimerMode();
if(tm==='hide')document.getElementById('timerNote').textContent='(timer hidden)';
if(tm==='pause-ok')document.getElementById('timerNote').textContent='(timer pauseable)';
});
function startExam(){
const byT={1:[],2:[],3:[],4:[],5:[]};
Q.forEach(q=>byT[q.t].push(q));
examQs=[];
[1,2,3,4,5].forEach(t=>{const sh=shuffle(byT[t]);examQs.push(...sh.slice(0,8));});
examQs=shuffle(examQs);
examAnswers=examQs.map(()=>null);
examMultiSel={};
examIdx=0;secondsLeft=3600;paused=false;
document.getElementById('startScreen').style.display='none';
document.getElementById('examSession').style.display='';
const tm=a11yTimerMode();
if(tm==='hide')document.getElementById('timer').style.display='none';
if(tm==='pause-ok')document.getElementById('pauseBtn').style.display='';
startTimer();renderQ();buildQMap();
}
function startTimer(){
timerInterval=setInterval(()=>{
if(paused)return;
secondsLeft--;
if(secondsLeft<=0){clearInterval(timerInterval);submitExam();return;}
updateTimer();
},1000);
updateTimer();
}
function togglePause(){
paused=!paused;
const btn=document.getElementById('pauseBtn');
btn.textContent=paused?'▶':'⏸';
btn.setAttribute('aria-label',paused?'Resume timer':'Pause timer');
}
function updateTimer(){
const m=Math.floor(secondsLeft/60),s=secondsLeft%60;
const el=document.getElementById('timer');
el.textContent=`${m}:${String(s).padStart(2,'0')}`;
el.classList.toggle('warn',secondsLeft<=300);
}
function srcBadge(q){
if(q.src==='obj') return '<span class="q-src-badge badge-ext">🎯 Obj</span>';
if(q.src==='own') return '<span class="q-src-badge badge-ext">✍ Own</span>';
if(q.src==='mat') return '<span class="q-src-badge badge-pdf">📕 Your pool</span>';
return '';
}
function renderQ(){
const q=examQs[examIdx];
const chosen=examAnswers[examIdx];
const t=q.t||1,col=TOPIC_COLORS[t];
const nAns=examAnswers.filter(a=>a!==null).length;
document.getElementById('examProg').style.width=`${(examIdx+1)/examQs.length*100}%`;
document.getElementById('examMeta').textContent=`Q${examIdx+1}/${examQs.length} · ${nAns} answered`;
document.getElementById('prevBtn').disabled=examIdx===0;
document.getElementById('nextBtn').textContent=examIdx===examQs.length-1?'Submit ✓':'Next →';
document.getElementById('examNavInfo').textContent=`${examIdx+1} / ${examQs.length}`;
const qtype=q.type||'mcq';
const typeBadge=qtype==='multi'?'<span class="q-src-badge badge-multi">☑ Multi-select</span>':
qtype==='fill' ?'<span class="q-src-badge badge-fill">✏ Fill-in</span>':'';
let optsHtml='';
if(qtype==='fill'){
const val=chosen&&chosen.val||'';
optsHtml=`<div class="fill-wrap">
<input type="text" id="examFillInput" class="fill-input" value="${escHtml(val)}" placeholder="Type your answer…" autocomplete="off" spellcheck="false" aria-label="Your answer">
<button class="btn outline sm" onclick="saveFill()">Save</button>
</div>
<div class="multi-hint muted small" role="note">Press Save or navigate to record your answer.</div>`;
}else if(qtype==='multi'){
const sel=examMultiSel[examIdx]||[];
optsHtml=`<div class="opts" role="group" aria-label="Select all correct answers">
${q.o.map((opt,oi)=>`
<button class="opt ${sel.includes(oi)?'chosen':''}" onclick="examToggleMulti(${oi})" aria-pressed="${sel.includes(oi)}">
<span class="opt-letter" style="${sel.includes(oi)?'background:var(--acc-dk);border-color:var(--acc-dk);color:#fff':''}" aria-hidden="true">${String.fromCharCode(65+oi)}</span>
<span>${formatQ(opt)}</span>
</button>`).join('')}
</div>
<div class="multi-hint muted small" role="note">Select ALL correct answers.</div>`;
}else{
optsHtml=`<div class="opts" role="radiogroup" aria-label="Answer options">
${q.o.map((opt,oi)=>`
<button class="opt ${chosen===oi?'chosen':''}" onclick="choose(${oi})" aria-pressed="${chosen===oi}">
<span class="opt-letter" style="${chosen===oi?'background:var(--acc-dk);border-color:var(--acc-dk);color:#fff':''}" aria-hidden="true">${String.fromCharCode(65+oi)}</span>
<span>${formatQ(opt)}</span>
</button>`).join('')}
</div>`;
}
document.getElementById('examQArea').innerHTML=`
<div class="q-card">
<div class="q-meta">
<span class="q-num">Q${examIdx+1}</span>
<span class="q-badge" style="background:${col.bg};color:${col.fg}">${TOPIC_NAMES[t]}</span>
${typeBadge}
${srcBadge(q)}
</div>
<div class="q-text" role="heading" aria-level="2">${formatQ(q.q)}</div>
${optsHtml}
</div>`;
if(qtype==='fill'){
const inp=document.getElementById('examFillInput');
if(inp)inp.addEventListener('keydown',e=>{if(e.key==='Enter')saveFill();});
}
updateQMap();
}
function escHtml(s){return(s||'').replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>');}
function choose(oi){examAnswers[examIdx]=oi;renderQ();}
function saveFill(){
const inp=document.getElementById('examFillInput');
if(inp&&inp.value.trim())examAnswers[examIdx]={val:inp.value.trim()};
renderQ();
}
function examToggleMulti(oi){
if(!examMultiSel[examIdx])examMultiSel[examIdx]=[];
const arr=examMultiSel[examIdx];
const i=arr.indexOf(oi);
if(i>=0)arr.splice(i,1);else arr.push(oi);
examAnswers[examIdx]=arr.length?[...arr]:null;
renderQ();
}
function examNav(dir){
const q=examQs[examIdx];
if((q.type||'mcq')==='fill'){
const inp=document.getElementById('examFillInput');
if(inp&&inp.value.trim()&&!examAnswers[examIdx])examAnswers[examIdx]={val:inp.value.trim()};
}
const n=examIdx+dir;
if(n<0)return;
if(n>=examQs.length){confirmSubmit();return;}
examIdx=n;renderQ();window.scrollTo({top:0,behavior:'smooth'});
}
function buildQMap(){
const map=document.getElementById('qMap');map.innerHTML='';
examQs.forEach((_,i)=>{
const btn=document.createElement('button');
btn.id=`qm${i}`;
const q=examQs[i];
const sym=q.type==='multi'?'☑':q.type==='fill'?'✏':'';
btn.innerHTML=`${i+1}<span style="font-size:9px">${sym}</span>`;
btn.setAttribute('aria-label',`Jump to question ${i+1}${sym?' ('+q.type+')':''}`);
btn.style.cssText='min-width:36px;height:36px;border-radius:6px;border:2px solid var(--border);background:var(--card);cursor:pointer;font-size:11px;font-weight:700;transition:all .1s;padding:0 4px;display:flex;align-items:center;justify-content:center;flex-direction:column;line-height:1';
btn.onclick=()=>{examIdx=i;renderQ();window.scrollTo({top:0,behavior:'smooth'});};
map.appendChild(btn);
});
}
function updateQMap(){
examQs.forEach((_,i)=>{
const btn=document.getElementById(`qm${i}`);if(!btn)return;
const isAns=examAnswers[i]!==null,isCur=i===examIdx;
btn.style.background=isCur?'var(--acc-dk)':isAns?'var(--green-lt)':'var(--card)';
btn.style.color=isCur?'#fff':isAns?'var(--green)':'var(--txt)';
btn.style.borderColor=isCur?'var(--acc-dk)':isAns?'var(--green)':'var(--border)';
});
}
function confirmSubmit(){
const unanswered=examAnswers.filter(a=>a===null).length;
if(unanswered>0&&!confirm(`${unanswered} unanswered question${unanswered>1?'s':''}. Submit anyway?`))return;
submitExam();
}
function submitExam(){
clearInterval(timerInterval);
document.getElementById('examSession').style.display='none';
let correct=0;
const byT={};[1,2,3,4,5].forEach(t=>byT[t]={c:0,t:0});
examQs.forEach((q,i)=>{
const t=q.t||1;byT[t].t++;
const a=examAnswers[i];const qt=q.type||'mcq';
let ok=false;
if(qt==='fill'){if(a&&a.val)ok=q.fill.some(f=>f.toLowerCase().trim()===a.val.toLowerCase().trim());}
else if(qt==='multi'){if(Array.isArray(a)){const aset=new Set(q.a),uset=new Set(a);ok=aset.size===uset.size&&[...aset].every(x=>uset.has(x));}}
else{ok=a===q.a;}
if(ok){correct++;byT[t].c++;}
});
const total=examQs.length,pct=Math.round(correct/total*100),passed=pct>=75;
const screen=document.getElementById('resultsScreen');screen.style.display='';
screen.innerHTML=`
<div class="card mb16 center">
<div class="score-big" style="color:${passed?'var(--green)':'var(--red)'}" aria-label="${correct} out of ${total}">${correct}/${total}</div>
<div class="score-pct">${pct}% — ${passed?'✅ PASS':'❌ FAIL'}</div>
<div class="score-msg">${passed?'🎉 You are ready for the real exam!':'📖 Keep practicing. Need 75% (30/40).'}</div>
<div class="breakdown" id="breakdown"></div>
<div class="btn-row" style="justify-content:center;flex-wrap:wrap">
<button class="btn accent" onclick="location.reload()">🔄 New Exam</button>
<button class="btn outline" onclick="showReview()">📋 Review Answers</button>
<a href="index.html" class="btn outline">🏠 Home</a>
</div>
</div>
<div id="reviewSection"></div>`;
const bd=document.getElementById('breakdown');
[1,2,3,4,5].forEach(t=>{
const col=TOPIC_COLORS[t],d=byT[t],div=document.createElement('div');
div.className='breakdown-item';div.style.cssText=`background:${col.bg};color:${col.fg}`;
const shortName={1:'Open Source',2:'Navigation',3:'CLI Power',4:'Linux OS',5:'Security'};
div.innerHTML=`<span class="breakdown-num">${d.c}/${d.t}</span><span class="breakdown-lbl">T${t} · ${shortName[t]}</span>`;
bd.appendChild(div);
});
}
function showReview(){
const section=document.getElementById('reviewSection');
section.innerHTML='<div class="section-hd mt24 mb8">Answer Review</div>';
examQs.forEach((q,i)=>{
const a=examAnswers[i];const qt=q.type||'mcq';
const t=q.t||1,col=TOPIC_COLORS[t];
let isCorrect=false,isSkipped=a===null;
if(!isSkipped){
if(qt==='fill'){isCorrect=a&&a.val&&q.fill.some(f=>f.toLowerCase().trim()===a.val.toLowerCase().trim());}
else if(qt==='multi'){const aset=new Set(q.a),uset=new Set(a||[]);isCorrect=aset.size===uset.size&&[...aset].every(x=>uset.has(x));}
else{isCorrect=a===q.a;}
}
const card=document.createElement('div');
card.className=`q-card ${isCorrect?'review-ok':isSkipped?'review-skip':'review-fail'}`;
let ansHtml='';
if(isSkipped){ansHtml='<span style="color:var(--warn)">Not answered</span>';}
else if(qt==='fill'){ansHtml=`<div style="font-size:13px">Your answer: <code>${escHtml(a?a.val:'(empty)')}</code><br>Correct: <code>${escHtml(q.fill[0])}</code></div>`;}
else if(qt==='multi'){
const chosen=Array.isArray(a)?a:[];
ansHtml=`<div style="font-size:13px">
<div>Your selection: ${chosen.map(i=>String.fromCharCode(65+i)).join(', ')||'none'}</div>
<div style="color:var(--green)">✓ Correct: ${q.a.map(i=>String.fromCharCode(65+i)).join(', ')}</div>
</div>`;
}else{
ansHtml=`<div style="font-size:13px">
${!isCorrect&&a!==null?`<div style="color:var(--red);margin-bottom:4px">Your: ${String.fromCharCode(65+a)}. ${formatQ(q.o[a])}</div>`:''}
<div style="color:var(--green)">✓ ${String.fromCharCode(65+q.a)}. ${formatQ(q.o[q.a])}</div>
</div>`;
}
card.innerHTML=`
<div class="q-meta">
<span class="q-num">${isCorrect?'✅':isSkipped?'⚠':'❌'} Q${i+1}</span>
<span class="q-badge" style="background:${col.bg};color:${col.fg}">${TOPIC_NAMES[t]}</span>
</div>
<div class="q-text" style="font-size:14px">${formatQ(q.q)}</div>
<div style="margin-top:10px">${ansHtml}</div>
<div class="exp show" style="margin-top:10px"><div class="exp-label">💡 Explanation</div>${formatQ(q.e||'')}</div>`;
section.appendChild(card);
});
}
</script>
</body>
</html>