-
Notifications
You must be signed in to change notification settings - Fork 0
/
bel.js
178 lines (156 loc) · 6.85 KB
/
bel.js
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
const quizData = [
{
question: 'Кое е правилното изписване на думата "разчупен"?',
options: ['разчупен', 'раз чупен', 'разчу пен', 'разчу пен'],
answer: 'разчупен',
},
{
question: 'Какво е синонимът на думата "бърз"?',
options: ['бавен', 'лек', 'бързомерен', 'ускорен'],
answer: 'ускорен',
},
{
question: 'Коя от следните думи е съществително?',
options: ['бързо', 'пътуване', 'летящ', 'играещ'],
answer: 'пътуване',
},
{
question: 'Какъв вид дума е "помагат"?',
options: ['съществително', 'прилагателно', 'глагол', 'наречие'],
answer: 'глагол',
},
{
question: 'Кое е правилното изписване на думата "пролет"?',
options: ['пролет', 'про лет', 'про лет', 'проле т'],
answer: 'пролет',
},
{
question: 'Кой от следните изрази е пряко допълнение?',
options: ['Момчето играе с кучето.', 'Хлапето отиде до магазина.', 'Момчето яде пица.', 'Кучето си лаяе в градината.'],
answer: 'Момчето яде пица.',
},
{
question: 'Кой от следните знаци се използва в края на изречение?',
options: ['Запетая (,)', 'Точка (.)', 'Въпросителна точка (?)', 'Тире (-)'],
answer: 'Точка (.)',
},
{
question: 'Каква е основната идея в стихотворението "Миг" от Иван Вазов?',
options: ['Животът е кратък и трябва да се наслаждаваме на моментите', 'Хората трябва да бъдат отговорни', 'Любовта е най-важната', 'Семейството е най-важното'],
answer: 'Животът е кратък и трябва да се наслаждаваме на моментите',
},
{
question: 'Как се казва авторът на "Дядо Йоцо и краката на куката"?',
options: ['Пенчо Славейков', 'Пейо Яворов', 'Иван Вазов', 'Йордан Йовков'],
answer: 'Йордан Йовков',
},
{
question: 'Кой от следните творци е писал поезия?',
options: ['Христо Ботев', 'Иван Вазов', 'Йордан Йовков', 'Елин Пелин'],
answer: 'Христо Ботев',
},
];
const quizContainer = document.getElementById('quiz');
const resultContainer = document.getElementById('result');
const submitButton = document.getElementById('submit');
const retryButton = document.getElementById('retry');
const showAnswerButton = document.getElementById('showAnswer');
let currentQuestion = 0;
let score = 0;
let incorrectAnswers = [];
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]];
}
}
function displayQuestion() {
const questionData = quizData[currentQuestion];
const questionElement = document.createElement('div');
questionElement.className = 'question';
questionElement.innerHTML = questionData.question;
const optionsElement = document.createElement('div');
optionsElement.className = 'options';
const shuffledOptions = [...questionData.options];
shuffleArray(shuffledOptions);
for (let i = 0; i < shuffledOptions.length; i++) {
const option = document.createElement('label');
option.className = 'option';
const radio = document.createElement('input');
radio.type = 'radio';
radio.name = 'quiz';
radio.value = shuffledOptions[i];
const optionText = document.createTextNode(shuffledOptions[i]);
option.appendChild(radio);
option.appendChild(optionText);
optionsElement.appendChild(option);
}
quizContainer.innerHTML = '';
quizContainer.appendChild(questionElement);
quizContainer.appendChild(optionsElement);
}
function checkAnswer() {
const selectedOption = document.querySelector('input[name="quiz"]:checked');
if (selectedOption) {
const answer = selectedOption.value;
if (answer === quizData[currentQuestion].answer) {
score++;
} else {
incorrectAnswers.push({
question: quizData[currentQuestion].question,
incorrectAnswer: answer,
correctAnswer: quizData[currentQuestion].answer,
});
}
currentQuestion++;
selectedOption.checked = false;
if (currentQuestion < quizData.length) {
displayQuestion();
} else {
displayResult();
}
}
}
function displayResult() {
quizContainer.style.display = 'none';
submitButton.style.display = 'none';
retryButton.style.display = 'inline-block';
showAnswerButton.style.display = 'inline-block';
resultContainer.innerHTML = `You scored ${score} out of ${quizData.length}!`;
}
function retryQuiz() {
currentQuestion = 0;
score = 0;
incorrectAnswers = [];
quizContainer.style.display = 'block';
submitButton.style.display = 'inline-block';
retryButton.style.display = 'none';
showAnswerButton.style.display = 'none';
resultContainer.innerHTML = '';
displayQuestion();
}
function showAnswer() {
quizContainer.style.display = 'none';
submitButton.style.display = 'none';
retryButton.style.display = 'inline-block';
showAnswerButton.style.display = 'none';
let incorrectAnswersHtml = '';
for (let i = 0; i < incorrectAnswers.length; i++) {
incorrectAnswersHtml += `
<p>
<strong>Question:</strong> ${incorrectAnswers[i].question}<br>
<strong>Your Answer:</strong> ${incorrectAnswers[i].incorrectAnswer}<br>
<strong>Correct Answer:</strong> ${incorrectAnswers[i].correctAnswer}
</p>
`;
}
resultContainer.innerHTML = `
<p>You scored ${score} out of ${quizData.length}!</p>
<p>Incorrect Answers:</p>
${incorrectAnswersHtml}
`;
}
submitButton.addEventListener('click', checkAnswer);
retryButton.addEventListener('click', retryQuiz);
showAnswerButton.addEventListener('click', showAnswer);
displayQuestion();