-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
869 lines (805 loc) · 37.1 KB
/
index.html
File metadata and controls
869 lines (805 loc) · 37.1 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
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
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Fiscal Council-Test</title>
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
line-height: 1.6;
color: #333;
max-width: 800px;
margin: 0 auto;
padding: 20px;
background-color: #f5f5f5;
}
.container {
background-color: white;
border-radius: 10px;
padding: 25px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}
h1 {
text-align: center;
color: #2c3e50;
margin-bottom: 30px;
}
.quiz-header {
margin-bottom: 25px;
text-align: center;
}
.question-container {
margin-bottom: 20px;
}
.options-container {
display: flex;
flex-direction: column;
gap: 10px;
margin-left: 15px;
}
.option {
padding: 10px 15px;
border: 1px solid #ddd;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s;
}
.option:hover {
background-color: #f0f0f0;
}
.option.selected {
background-color: #3498db;
color: white;
border-color: #2980b9;
}
.controls {
display: flex;
justify-content: space-between;
margin-top: 30px;
}
.btn {
padding: 10px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
transition: background-color 0.3s;
}
.btn-primary {
background-color: #3498db;
color: white;
}
.btn-primary:hover {
background-color: #2980b9;
}
.btn-secondary {
background-color: #95a5a6;
color: white;
}
.btn-secondary:hover {
background-color: #7f8c8d;
}
.btn-success {
background-color: #2ecc71;
color: white;
}
.btn-success:hover {
background-color: #27ae60;
}
.progress-bar {
height: 10px;
background-color: #ecf0f1;
border-radius: 5px;
margin-bottom: 20px;
overflow: hidden;
}
.progress {
height: 100%;
background-color: #e46938;
transition: width 0.3s ease;
}
.start-screen, .quiz-screen, .results-screen {
display: none;
}
.start-screen.active, .quiz-screen.active, .results-screen.active {
display: block;
}
.result-info {
text-align: center;
margin-bottom: 20px;
}
.result-score {
font-size: 24px;
font-weight: bold;
color: #2c3e50;
margin: 20px 0;
}
.answers-review {
margin-top: 30px;
}
.answer-item {
margin-bottom: 15px;
padding: 15px;
border-radius: 5px;
}
.correct {
background-color: rgba(46, 204, 113, 0.2);
}
.incorrect {
background-color: rgba(231, 76, 60, 0.2);
}
.user-answer {
font-weight: bold;
}
.correct-answer {
color: #27ae60;
font-weight: bold;
}
#user-name {
width: 100%;
padding: 10px;
border: 1px solid #ddd;
border-radius: 5px;
margin-bottom: 20px;
font-size: 16px;
}
.timer {
text-align: center;
font-size: 20px;
font-weight: bold;
margin-bottom: 15px;
color: #2c3e50;
}
.timer.warning {
color: #e67e22;
}
.timer.danger {
color: #e74c3c;
animation: pulse 1s infinite;
}
@keyframes pulse {
0% { opacity: 1; }
50% { opacity: 0.5; }
100% { opacity: 1; }
}
.quiz-setup {
margin-top: 20px;
padding: 20px;
border: 1px solid #ddd;
border-radius: 5px;
background-color: #f9f9f9;
}
.form-group {
margin-bottom: 15px;
}
label {
display: block;
margin-bottom: 5px;
font-weight: bold;
}
select, input[type="number"] {
width: 100%;
padding: 8px;
border: 1px solid #ddd;
border-radius: 4px;
font-size: 16px;
}
</style>
</head>
<body>
<div class="container">
<!-- Start Screen -->
<div class="start-screen active">
<img src="fiscal_council_cy_logo.png" alt="Fiscal Council Logo" class="logo">
<h1>Charter Fiscal Analyst/CFA Programme - Basic Examination</h1>
<div class="quiz-header">
<p>This mock examination consists of 10 multiple-choice questions and is proudly endorsed by the Fiscal Council. Assess your expertise and demonstrate your readiness for the Charter Fiscal Analyst Programme - Level I</p>
<p>The Fiscal Council recognizes the Charter Fiscal Analyst Programme - Level I certification as a mandatory qualification for all candidates applying for council positions. This certification reflects the rigorous knowledge and expertise required to excel in fiscal policy and economic analysis.</p>
<p>This certification program has been officially approved by the Board of the Fiscal Council, under the leadership of President , with the support of esteemed members Professor and Economist.</p>
<p>Enter your name to begin:</p>
<div class="quiz-setup">
<div class="form-group">
<label for="user-name">Your Name:</label>
<input type="text" id="user-name" placeholder="Enter your name">
</div>
<div class="form-group">
<label for="question-count">Number of Questions:</label>
<input type="number" id="question-count" min="5" max="10" value="10">
</div>
<div class="form-group">
<label for="time-limit">Time Limit (minutes):</label>
<input type="number" id="time-limit" min="5" max="120" value="60">
</div>
</div>
<p><strong>Note:</strong> Questions will be randomly selected from our question bank.</p>
<button id="start-btn" class="btn btn-primary">Start Test</button>
</div>
</div>
<!-- Quiz Screen -->
<div class="quiz-screen">
<div class="timer" id="timer">Time remaining: 60:00</div>
<div class="progress-bar">
<div class="progress" id="progress"></div>
</div>
<h2 id="question-text">Question goes here</h2>
<div class="options-container" id="options-container">
<!-- Options will be inserted here -->
</div>
<div class="controls">
<button id="prev-btn" class="btn btn-secondary">Previous</button>
<button id="next-btn" class="btn btn-primary">Next</button>
<button id="submit-btn" class="btn btn-success" style="display: none;">Submit Test</button>
</div>
</div>
<!-- Results Screen -->
<div class="results-screen">
<h1>Test Results</h1>
<div class="result-info">
<p>Congratulations on completing the test!</p>
<div class="result-score">
Your Score: <span id="score">0</span> / <span id="total-questions">10</span>
</div>
<p id="score-percentage"></p>
<p id="time-taken"></p>
<button id="review-btn" class="btn btn-primary">Review Answers</button>
<button id="restart-btn" class="btn btn-secondary">Take Test Again</button>
</div>
<div class="answers-review" id="answers-review" style="display: none;">
<!-- Review of answers will be inserted here -->
</div>
</div>
</div>
<script>
// Complete question bank - Add as many questions as you want
const questionBank = [
{
"question": "Which of the following is a key preventive measure under Stability and Growth Pact (SGP)?",
"options": [
"Excessive Deficit Procedure",
"Medium Term Budgetary Objective",
"Debt Sustainability Analysis",
"Fiscal Compact"
],
"answer": "Medium Term Budgetary Objective"
},
{
"question": "What is the maximum allowable budget deficit for EU member states under the Stability and Growth Pact?",
"options": [
"1% of GDP",
"2% of GDP",
"3% of GDP",
"4% of GDP"
],
"answer": "3% of GDP"
},
{
"question": "Which institution is responsible for monitoring compliance with the Stability and Growth Pact?",
"options": [
"European Central Bank",
"European Commission",
"European Parliament",
"European Council"
],
"answer": "European Commission"
},
{
"question": "What is the primary goal of the Excessive Deficit Procedure (EDP) under the Stability and Growth Pact?",
"options": [
"To reduce inflation rates",
"To ensure sustainable economic growth",
"To correct excessive budget deficits",
"To harmonize tax policies"
],
"answer": "To correct excessive budget deficits"
},
{
"question": "Which of the following criteria is used to assess compliance with the Stability and Growth Pact?",
"options": [
"Unemployment rate",
"Public debt-to-GDP ratio",
"Trade Balance",
"Interest rate"
],
"answer": "Public debt-to-GDP ratio"
},
{
"question": "What is the purpose of the medium-term budgetary objective (MTBO) under the Stability and Growth Pact (SGP)?",
"options": [
"To ensure member states maintain their annual budget deficit below 3% of GDP.",
"To set specific fiscal targets that promote sustainable public finances over a medium-term horizon.",
"To calculate debt-to-GDP ratios solely based on short-term economic conditions.",
"To focus exclusively on reducing public debt without addressing other fiscal challenges."
],
"answer": "Public debt-to-GDP ratio"
},
{
"question": "If debt exceeds 60% of GDP under the Stability and Growth Pact (SGP), what is required of member states?",
"options": [
"To immediately eliminate their budget deficit within the same fiscal year.",
"To reduce the excess debt by at least 1/20th per year on average, as part of the debt reduction benchmark.",
"To submit a new medium-term budgetary objective (MTBO) that targets a zero budget deficit.",
"To increase short-term borrowing to stabilize economic growth."
],
"answer": "To reduce the excess debt by at least 1/20th per year on average, as part of the debt reduction benchmark."
},
{
"question": "What is the primary function of the preventive arm of the Stability and Growth Pact (SGP)?",
"options": [
"To provide financial assistance to member states facing economic crises.",
"To enforce penalties on member states that exceed the debt-to-GDP threshold.",
"To monitor fiscal policies and ensure sound budgetary planning to avoid excessive deficits.",
"To regulate trade imbalances between EU member states."
],
"answer": "To monitor fiscal policies and ensure sound budgetary planning to avoid excessive deficits."
},
{
"question": "Under the preventive arm of the new Stability and Growth Pact (SGP), what is the primary purpose of requiring member states to submit national medium-term fiscal-structural plans?",
"options": [
"To ensure fiscal plans include a detailed breakdown of annual expenditure per ministry.",
"To align fiscal-structural planning with national executive terms and promote medium-term budgetary objectives over a 4\ufffd5 year horizon.",
"To centralize fiscal decision-making within the European Commission for enhanced oversight.",
"To provide immediate solutions for managing short-term budget deficits in member states."
],
"answer": "To monitor fiscal policies and ensure sound budgetary planning to avoid excessive deficits."
},
{
"question": "Which of the following is NOT typically included in a country\ufffds national policies?",
"options": [
"Public spending programs aimed at improving infrastructure and public services.",
"Taxation systems designed to generate government revenue.",
"Monetary policy decisions, such as interest rate setting and money supply control.",
"Social safety nets to support vulnerable populations and reduce inequality."
],
"answer": "Monetary policy decisions, such as interest rate setting and money supply control."
},
{
"question": "What is the primary distinction between the preventive arm and the corrective arm of the Stability and Growth Pact (SGP)?",
"options": [
"The preventive arm focuses on ensuring member states avoid excessive deficits, while the corrective arm enforces penalties for non-compliance with fiscal rules.",
"The preventive arm regulates public debt levels, while the corrective arm sets inflation rate targets.",
"The preventive arm promotes currency stabilization, while the corrective arm manages trade agreements among member states.",
"The preventive arm addresses structural reforms, while the corrective arm focuses solely on employment policies."
],
"answer": "The preventive arm focuses on ensuring member states avoid excessive deficits, while the corrective arm enforces penalties for non-compliance with fiscal rules."
},
{
"question": "Which of the following is NOT addressed by the corrective arm of the Stability and Growth Pact (SGP)?",
"options": [
"Situations where the budget deficit exceeds 3% of GDP.",
"Debt levels that are too high and do not follow the reduction benchmark of 1/20th annually.",
"The design and implementation of structural reforms to boost economic growth.",
"Actions such as launching the Excessive Deficit Procedure (EDP) to enforce compliance and recommend corrective measures."
],
"answer": "The preventive arm focuses on ensuring member states avoid excessive deficits, while the corrective arm enforces penalties for non-compliance with fiscal rules."
},
{
"question": "Which of the following is a key focus of EU priorities in fiscal strategies?",
"options": [
"Increasing Military Spending",
"Green and Digital Transitions",
"Reducing immigration",
"Expanding agricultural subsidies"
],
"answer": "Green and Digital Transitions"
},
{
"question": "What aspect is NOT typically included in structural reforms under EU priorities?",
"options": [
"Improving Social Resilience",
"Enhancing defense capabilities",
"Promoting digital transitions",
"Increasing trade tariffs"
],
"answer": "Increasing trade tariffs"
},
{
"question": "Which of the following investments aligns with EU priorities?",
"options": [
"Investing in fossil fuel infrastructure",
"Investing in renewable energy resources",
"Investing in traditional manufacturing",
"Investing in non-digital communication methods"
],
"answer": "Investing in renewable energy resources"
},
{
"question": "What is a primary goal of social resilience initiatives under EU priorities?",
"options": [
"Reducing defense spending",
"Supporting vulnerable populations",
"Increasing corporate profits",
"Expanding agricultural land"
],
"answer": "Supporting vulnerable populations"
},
{
"question": "Which of the following is a focus area for defense capabilities under EU priorities?",
"options": [
"Enhancing cybersecurity measures",
"Reducing public transportation funding",
"Increasing agricultural exports",
"Promoting fossil fuel usage"
],
"answer": "Enhancing cybersecurity measures"
},
{
"question": "What is the primary purpose of the net expenditure path as a single country-specific operational indicator under the revised fiscal framework?",
"options": [
"To replace the debt sustainability analysis (DSA) with simplified fiscal rules that focus only on short-term growth.",
"To eliminate the need for monitoring fiscal policies by aligning with pre-existing EU-wide benchmarks.",
"To simplify fiscal surveillance by providing a country-specific operational tool rooted in debt sustainability analysis (DSA).",
"To introduce a uniform fiscal indicator applicable equally to all EU member states regardless of national contexts."
],
"answer": "To simplify fiscal surveillance by providing a country-specific operational tool rooted in debt sustainability analysis (DSA)."
},
{
"question": "What does the net expenditure path include as a country-specific operational indicator under the revised fiscal framework?",
"options": [
"Total government revenue projections, excluding public investments.",
"Adjusted expenditure growth limits aligned with medium-term fiscal objectives and Debt Sustainability Analysis (DSA).",
"A fixed expenditure cap applicable uniformly across all EU member states.",
"Short-term fiscal policies designed to manage immediate economic crises."
],
"answer": "Adjusted expenditure growth limits aligned with medium-term fiscal objectives and Debt Sustainability Analysis (DSA)."
},
{
"question": "Which of the following is included in the definition of net expenditure path?",
"options": [
"Discretionary revenue measures.",
"Interest expenditure.",
"Cyclical unemployment expenditure.",
"Investments in infrastructure and public services."
],
"answer": "Investments in infrastructure and public services."
},
{
"question": "Which of the following is NOT required to calculate the maximum allowed limit for annual nominal net primary expenditure growth using the specified formula?",
"options": [
"Yearly Potential GDP growth",
"Yearly Real GDP growth",
"GDP deflator",
"primary expenditure-to-GDP ratio"
],
"answer": "Yearly Real GDP growth"
},
{
"question": "A debt-based EDP can be triggered if a member state's debt-to-GDP ratio is above __ along with a budget balance deficit, and the member state's control account deviates from the country-specific agreed Net Expenditure Path by ____ percentage points of GDP annually, or ___ percentage points of GDP cumulatively?",
"options": [
"0.3, 0.6, 0.6",
"60%, 0.6, 0.3",
"0.6, 0.3, 0.6",
"0.4, 0.3, 0.6"
],
"answer": "0.6, 0.3, 0.6 "
},
{
"question": "Which of the following scenarios would trigger an Excessive Deficit Procedure",
"options": [
"65% Debt-to-GDP",
"55% Debt-to-GDP",
"3% of GDP deficit",
"1.2% of GDP deficit"
],
"answer": "3% of GDP deficit"
},
{
"question": "Which of the following assumptions is NOT part of the baseline for debt sustainability analysis?",
"options": [
"Real GDP growth rates derived from potential growth estimates using the EPC/OGWG T+10 methodology",
"Inflation converging linearly to market-based euro inflation expectations by T+10 and to the ECB's 2% target by T+30",
"Structural primary balance (SPB) remaining constant before costs of ageing and adjusted for property income on government assets",
"Automatic stabilizers causing a permanent effect on the cyclical component of the budget balance, regardless of output gap closure."
],
"answer": "Automatic stabilizers causing a permanent effect on the cyclical component of the budget balance, regardless of output gap closure."
},
{
"question": "What does the cyclical component of the budget balance reflect in the context of debt sustainability analysis?",
"options": [
"The impact of discretionary fiscal measures implemented by the government.",
"Automatic stabilizers based on the output gap and country-specific budget balance semi-elasticities.",
"Long-term structural expenditures related to ageing and property income on assets.",
"Fixed adjustments unrelated to economic fluctuations or changes in GDP."
],
"answer": "Automatic stabilizers based on the output gap and country-specific budget balance semi-elasticities."
},
{
"question": "What is being described when it measures the absolute change of a variable (e.g., the budget-to-GDP ratio) as a result of the relative change of another variable (e.g., GDP)?",
"options": [
"Budget elasticity.",
"Budget balance semi-elasticity.",
"Structural primary balance.",
"Debt-to-GDP ratio threshold."
],
"answer": "Automatic stabilizers based on the output gap and country-specific budget balance semi-elasticities."
},
{
"question": "What assumption is made about long-term interest rates on new and rolled-over debt in the baseline for debt sustainability analysis?",
"options": [
"They remain constant at country-specific current values throughout the projection period",
"They linearly converge to country-specific market-based forward nominal rates by T+10 and to 4% nominal (2% real) by T+30",
"They are directly tied to short-term interest rate fluctuations over the entire projection period.",
"They converge to the ECB's 2% inflation target in nominal terms by T+10 and remain there permanently."
],
"answer": "Automatic stabilizers based on the output gap and country-specific budget balance semi-elasticities."
},
{
"question": "How are implicit interest rates determined in the debt projection model?",
"options": [
"They are set directly by policymakers to align with inflation targets.",
"They are derived endogenously based on market interest rates, government debt maturity structure, and projected financing needs.",
"They are fixed at the average rate of historical government bond yields.",
"They are calculated using only the nominal GDP growth rate and fiscal deficits."
],
"answer": "They are derived endogenously based on market interest rates, government debt maturity structure, and projected financing needs."
},
{
"question": "What does the baseline (no-fiscal-policy-change assumption) refer to in fiscal analysis?",
"options": [
"A scenario where government policies are adjusted annually to meet economic targets.",
"A reference scenario assuming that spending and tax policies remain constant over the analysis period.",
"A projection that includes significant reforms to fiscal policies and economic structures.",
"A theoretical model assuming that fiscal deficits and public debt are eliminated entirely"
],
"answer": "A reference scenario assuming that spending and tax policies remain constant over the analysis period."
},
{
"question": "What is the primary purpose of fiscal policy scenarios in economic analysis?",
"options": [
"To maintain a constant projection of economic outcomes without adjusting government policies.",
"To explore alternative projections involving changes to government spending and/or tax policies and their impact on the economy.",
"To model fixed revenue streams regardless of economic changes.",
"To eliminate the effects of economic shocks by assuming a balanced budget throughout the period."
],
"answer": "To explore alternative projections involving changes to government spending and/or tax policies and their impact on the economy"
},
{
"question": "What does fiscal consolidation involve?",
"options": [
"Implementing measures to reduce government budget deficits and stabilize public debt.",
"Expanding public sector spending and increasing government investment in infrastructure projects.",
"Decreasing tax rates and creating exemptions to promote fiscal growth.",
"Maintaining constant fiscal policies to prevent fluctuations in the economy."
],
"answer": "Implementing measures to reduce government budget deficits and stabilize public debt."
}
];
// Variables
let currentQuestion = 0;
let userAnswers = [];
let timerInterval;
let startTime;
let timeLeft = 60 * 60; // Default: 1 hour in seconds
let selectedQuestions = []; // Will hold the randomly selected questions
// DOM Elements
const startScreen = document.querySelector('.start-screen');
const quizScreen = document.querySelector('.quiz-screen');
const resultsScreen = document.querySelector('.results-screen');
const userName = document.getElementById('user-name');
const questionCount = document.getElementById('question-count');
const timeLimit = document.getElementById('time-limit');
const startBtn = document.getElementById('start-btn');
const prevBtn = document.getElementById('prev-btn');
const nextBtn = document.getElementById('next-btn');
const submitBtn = document.getElementById('submit-btn');
const questionText = document.getElementById('question-text');
const optionsContainer = document.getElementById('options-container');
const progress = document.getElementById('progress');
const score = document.getElementById('score');
const totalQuestions = document.getElementById('total-questions');
const scorePercentage = document.getElementById('score-percentage');
const reviewBtn = document.getElementById('review-btn');
const restartBtn = document.getElementById('restart-btn');
const answersReview = document.getElementById('answers-review');
const timerElement = document.getElementById('timer');
const timeTaken = document.getElementById('time-taken');
// Event Listeners
startBtn.addEventListener('click', startQuiz);
prevBtn.addEventListener('click', goToPrevQuestion);
nextBtn.addEventListener('click', goToNextQuestion);
submitBtn.addEventListener('click', submitQuiz);
reviewBtn.addEventListener('click', toggleReview);
restartBtn.addEventListener('click', restartQuiz);
// Fisher-Yates shuffle algorithm for randomizing questions
function shuffleArray(array) {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
return array;
}
// Initialize Quiz
function startQuiz() {
if (userName.value.trim() === '') {
alert('Please enter your name to start the quiz');
return;
}
// Get user preferences
const numQuestions = parseInt(questionCount.value);
const minutes = parseInt(timeLimit.value);
// Validate inputs
if (isNaN(numQuestions) || numQuestions < 5 || numQuestions > 30) {
alert('Please select between 5 and 30 questions');
return;
}
if (isNaN(minutes) || minutes < 5 || minutes > 120) {
alert('Please select a time limit between 5 and 120 minutes');
return;
}
// Set time limit
timeLeft = minutes * 60;
// Select random questions
const shuffledQuestions = shuffleArray([...questionBank]);
selectedQuestions = shuffledQuestions.slice(0, numQuestions);
// Reset user answers array
userAnswers = Array(selectedQuestions.length).fill(null);
startScreen.classList.remove('active');
quizScreen.classList.add('active');
totalQuestions.textContent = selectedQuestions.length;
startTime = new Date();
startTimer();
currentQuestion = 0;
loadQuestion();
}
// Load Question
function loadQuestion() {
const question = selectedQuestions[currentQuestion];
questionText.textContent = `Question ${currentQuestion + 1}: ${question.question}`;
optionsContainer.innerHTML = '';
question.options.forEach((option, index) => {
const optionElement = document.createElement('div');
optionElement.classList.add('option');
optionElement.textContent = option;
if (userAnswers[currentQuestion] === option) {
optionElement.classList.add('selected');
}
optionElement.addEventListener('click', () => {
selectOption(option);
});
optionsContainer.appendChild(optionElement);
});
updateProgress();
updateButtons();
}
// Select Option
function selectOption(selectedOption) {
userAnswers[currentQuestion] = selectedOption;
document.querySelectorAll('.option').forEach(option => {
option.classList.remove('selected');
if (option.textContent === selectedOption) {
option.classList.add('selected');
}
});
}
// Update Progress
function updateProgress() {
const progressPercentage = ((currentQuestion + 1) / selectedQuestions.length) * 100;
progress.style.width = `${progressPercentage}%`;
}
// Update Buttons
function updateButtons() {
prevBtn.disabled = currentQuestion === 0;
if (currentQuestion === selectedQuestions.length - 1) {
nextBtn.style.display = 'none';
submitBtn.style.display = 'block';
} else {
nextBtn.style.display = 'block';
submitBtn.style.display = 'none';
}
}
// Timer Functions
function startTimer() {
updateTimerDisplay();
timerInterval = setInterval(updateTimer, 1000);
}
function updateTimer() {
timeLeft--;
updateTimerDisplay();
// Time's up
if (timeLeft <= 0) {
clearInterval(timerInterval);
alert("Time's up! Your quiz will be submitted now.");
submitQuiz();
}
}
function updateTimerDisplay() {
const minutes = Math.floor(timeLeft / 60);
const seconds = timeLeft % 60;
timerElement.textContent = `Time remaining: ${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
// Warning colors
timerElement.classList.remove('warning', 'danger');
const totalSeconds = parseInt(timeLimit.value) * 60;
const percentLeft = (timeLeft / totalSeconds) * 100;
if (percentLeft <= 5) { // Last 5% of time
timerElement.classList.add('danger');
} else if (percentLeft <= 15) { // Last 15% of time
timerElement.classList.add('warning');
}
}
function stopTimer() {
clearInterval(timerInterval);
// Calculate time taken
const endTime = new Date();
const timeDiff = Math.floor((endTime - startTime) / 1000); // in seconds
const minutesTaken = Math.floor(timeDiff / 60);
const secondsTaken = timeDiff % 60;
timeTaken.textContent = `Time taken: ${minutesTaken} minutes and ${secondsTaken} seconds`;
}
// Navigate to Previous Question
function goToPrevQuestion() {
if (currentQuestion > 0) {
currentQuestion--;
loadQuestion();
}
}
// Navigate to Next Question
function goToNextQuestion() {
if (currentQuestion < selectedQuestions.length - 1) {
currentQuestion++;
loadQuestion();
}
}
// Submit Quiz
function submitQuiz() {
// Stop the timer
stopTimer();
// Check if all questions are answered
const unansweredQuestions = userAnswers.findIndex(answer => answer === null);
if (unansweredQuestions !== -1) {
if (confirm(`You have not answered question ${unansweredQuestions + 1}. Do you want to go back and answer it?`)) {
currentQuestion = unansweredQuestions;
loadQuestion();
return;
}
}
quizScreen.classList.remove('active');
resultsScreen.classList.add('active');
calculateResults();
}
// Calculate Results
function calculateResults() {
let correctAnswers = 0;
userAnswers.forEach((answer, index) => {
if (answer === selectedQuestions[index].answer) {
correctAnswers++;
}
});
score.textContent = correctAnswers;
const percentage = (correctAnswers / selectedQuestions.length) * 100;
scorePercentage.textContent = `You scored ${percentage.toFixed(2)}%`;
generateReview();
}
// Generate Review
function generateReview() {
answersReview.innerHTML = '';
userAnswers.forEach((answer, index) => {
const question = selectedQuestions[index];
const isCorrect = answer === question.answer;
const reviewItem = document.createElement('div');
reviewItem.classList.add('answer-item');
reviewItem.classList.add(isCorrect ? 'correct' : 'incorrect');
reviewItem.innerHTML = `
<p><strong>Question ${index + 1}:</strong> ${question.question}</p>
<p>Your answer: <span class="user-answer">${answer || 'Not answered'}</span></p>
${!isCorrect ? `<p>Correct answer: <span class="correct-answer">${question.answer}</span></p>` : ''}
`;
answersReview.appendChild(reviewItem);
});
}
// Toggle Review Display
function toggleReview() {
const isHidden = answersReview.style.display === 'none';
answersReview.style.display = isHidden ? 'block' : 'none';
reviewBtn.textContent = isHidden ? 'Hide Answers' : 'Review Answers';
}
// Restart Quiz
function restartQuiz() {
currentQuestion = 0;
resultsScreen.classList.remove('active');
startScreen.classList.add('active');
answersReview.style.display = 'none';
reviewBtn.textContent = 'Review Answers';
}
</script>
</body>
</html>