-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
247 lines (229 loc) · 10.1 KB
/
script.js
File metadata and controls
247 lines (229 loc) · 10.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
const questionText = document.getElementById('question-text');
const picture = document.getElementById('picture');
const answersContainer = document.getElementById('answers-container');
const backBtn = document.getElementById('back-btn');
const nextBtn = document.getElementById('next-btn');
const scoreText = document.getElementById('answers-and-image-container');
const questions = [
{
question: 'Сколько лет Хатико ждал своего хозяина после его смерти в фильме "Хатико: Самый верный друг"?',
answers: [
{text: '12 лет', correct: false},
{text: '7 лет', correct: false},
{text: '9 лет', correct: true},
{text: '4 года', correct: false}
],
img: "./img/1.webp"
},
{
question: 'Как Джеку удалось попасть на корабль из фильма "Титаник"?',
answers: [
{text: 'Он пробрался тайком', correct: false},
{text: 'Он купил билет на последние деньги', correct: false},
{text: 'Он выиграл билет в покер', correct: true},
{text: 'Он украл билет', correct: false}
],
img: './img/2.webp'
},
{
question: 'Какой предмет появляеться в каждой сцене фильма "Бойцовский клуб"?',
answers: [
{text: 'Бутылка "Coca-Cola"', correct: false},
{text: 'Чизбургер "McDonalds"', correct: false},
{text: 'Пачка сигарет "Marlboro"', correct: false},
{text: 'Стаканчик "Starbucks"', correct: true}
],
img: './img/3.webp'
},
{
question: 'Какова марка автомобиля, который отиграл роль машины времени из фильма "Назад в будущее"?',
answers: [
{text: 'DeLorean DMC-12', correct: true},
{text: 'Audi quattro', correct: false},
{text: 'BMW 750iL (E38)', correct: false},
{text: 'ВАЗ-2121', correct: false}
],
img: './img/4.webp'
},
{
question: 'Какое боевое искусство первым загрузили в мозг Нео в фильме "Матрица"?',
answers: [
{text: 'Айкиду', correct: false},
{text: 'Капоэйра', correct: false},
{text: 'Джиу-джитсу', correct: true},
{text: 'Каратэ', correct: false}
],
img: './img/5.webp'
},
{
question: 'Как называется эльфийский (волшебный) хлеб из трилогии фильмов "Властелин Колец"?',
answers: [
{text: 'Лемиш', correct: false},
{text: 'Лембас', correct: true},
{text: 'Люмбаш', correct: false},
{text: 'Любэ', correct: false}
],
img: './img/6.webp'
},
{
question: 'Какую фразу говорил Трумэн соседям если не увидит их, в фильме "Шоу Трумана"?',
answers: [
{text: '"Никогда не говорите никогда!"', correct: false},
{text: '"Ещё увидимся!"', correct: false},
{text: '"Доброе утроб добрый день и добрый вечер!"', correct: true},
{text: '"Я буду по Вам скучать!"', correct: false}
],
img: './img/7.jpeg'
},
{
question: 'Где, по мнению главного героя "Остров проклятых", размещена тайная лаборатория для экспериментов?',
answers: [
{text: 'На маяке', correct: true},
{text: 'В бункере', correct: false},
{text: 'Под кладбищем', correct: false},
{text: 'В шахте', correct: false}
],
img: './img/8.webp'
},
{
question: 'В какую «фруктовую компанию» лейтенант Дэн инвестирует деньги Форреста из фильма "Форест Гамп"?',
answers: [
{text: 'Orange', correct: false},
{text: 'Banana', correct: false},
{text: 'Apple', correct: true},
{text: 'Grape', correct: false}
],
img: './img/9.webp'
},
{
question: 'Сколько времени провёл в плену Тони Старк в трилогии "Железный Человек"?',
answers: [
{text: 'был убит в плену', correct: false},
{text: 'три месяца', correct: true},
{text: 'два года', correct: false},
{text: 'две недели', correct: false}
],
img: './img/10.webp'
},
{
question: 'Какой фрукт является символом смерти в трилогии "Крёстный отец"?',
answers: [
{text: 'Апельсин', correct: true},
{text: 'Банан', correct: false},
{text: 'Яблоко', correct: false},
{text: 'Лимон', correct: false}
],
img: './img/11.webp'
},
{
question: 'Что украл Дрисс у Филиппа - аристократа миллионера в фильме "1+1"?',
answers: [
{text: 'Жизнь', correct: false},
{text: 'Яйцо Фаберже', correct: true},
{text: 'Картину художника Джексон Поллок «№ 5»', correct: false},
{text: 'Машину', correct: false}
],
img: './img/12.webp'
}/*,
{
question: 'Сколько лет Хатико ждал своего хозяина после его смерти в фильме "Хатико: Самый верный друг"?',
answers: [
{text: '12 лет', correct: false},
{text: '7 лет', correct: false},
{text: '9 лет', correct: true},
{text: '4 года', correct: false}
],
img: './img/1.webp'
}*/
];
let currentQuestionIndex = 0;
let score = 0;
const startQuiz = () => {
currentQuestionIndex = 0;
score = 0;
showQuestions();
}
const showQuestions = () => {
resetState();
let currentQuestion = questions[currentQuestionIndex];
let questionNo = currentQuestionIndex + 1;
questionText.innerHTML = questionNo + '. ' + currentQuestion.question;
picture.innerHTML = `<img src='${currentQuestion.img}' class='img-question'>`;
currentQuestion.answers.forEach((answer) => {
const button = document.createElement('button');
button.innerHTML = answer.text;
button.classList.add('answer-btn');
answersContainer.appendChild(button);
if (answer.correct) {
button.dataset.correct = answer.correct;
}
button.addEventListener('click', selectAnswer);
});
}
const resetState = () => {
while (answersContainer.firstChild) {
answersContainer.removeChild(answersContainer.firstChild);
}
}
const selectAnswer = (e) => {
const selectBtn = e.target;
const isCorrect = selectBtn.dataset.correct === 'true';
if (isCorrect) {
selectBtn.classList.add('correct');
score++;
}
Array.from(answersContainer.children).forEach(button => {
if (button.dataset.correct === 'true') {
button.classList.add('correct');
}
button.disabled = true;
});
}
const showScore = () => {
resetState();
questionText.innerHTML = `Вы набрали ${score} из ${questions.length}`;
if (score <= 12 && score > 8) {
scoreText.innerHTML = `
<div class='text-score'>
<h1>Вы настоящий киноман!</h1>
<p>На большое количество вопросов Вы ответили верно. Похоже просмотр фильмов - одно из ваших любимых занятий!</p>
</div>
`;
answersContainer.remove();
} else if (score <= 7 && score >= 3) {
picture.innerHTML = `
<div class='text-score'>
<h1>Иногда Вы не прочь посмотреть фильмы</h1>
<p>Ярым фанатом кинематографа Вас, конечно, нельзя назвать. Однако просмотр фильмов Вас явно не чужд, и в свободное время Вы не прочь посмотреть кино.</p>
</div>
`;
answersContainer.remove();
} else if (score <= 2 && score >= 0) {
picture.innerHTML = `
<div class='text-score'>
<h1>Похоже Вы не любитель кино</h1>
<p>Назвать просмотр фильмов вашим увлечением, можно лишь с большим преувеличением. Выделить время специально для просмотра фильма - похоже не про Вас. Возможно, Вам нравится читать книги, либо Вы имеете какое-то другое хобби</p>
</div>
`;
answersContainer.remove();
}
nextBtn.addEventListener('click', () => {
location.reload();
});
}
const nextQuestion = () => {
currentQuestionIndex++;
if (currentQuestionIndex < questions.length) {
showQuestions();
} else {
showScore();
}
}
nextBtn.addEventListener('click', () => {
if (currentQuestionIndex < questions.length) {
nextQuestion();
} else {
startQuiz();
}
});
startQuiz();