-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
115 lines (84 loc) · 3.96 KB
/
script.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
page.title = 'тестер)'
engine.createHeader("привет, давай проверим твои знания :)");
engine.createText('cайтик для зубрёжки путём прохождения тестов');
engine.createButton('Создать свой тест').onClick(() => {
document.location.search = new URLSearchParams();
});
engine.space(2);
params = new URLSearchParams(document.location.search);
if (params.has('length')) {
const name = params.get('name');
const author = params.get('author');
const length = parseInt(params.get('length'), 10);
engine.createHeader(`${name} (тест сделал: ${author})`);
const start_test = engine.createButton('Начать');
const question_text = engine.createText('a').hide();
const answer_input = engine.createInput.text().hide();
const answer_button = engine.createInput.button("ответить").hide();
start_test.onClick(() => {
start_test.hide();
types = [...params.getAll('0')]
data = [];
for (let i = 1; i < length; i++) {
data.push([...params.getAll(i.toString())])
}
let question = 1;
question_text.show();
answer_input.show();
answer_button.show();
function newQuestion() {
const element = data[utils.random(0, data.length-1)];
let ask = utils.random(0, types.length-1);
let answer = utils.random(0, types.length-1);
if (answer == ask) ask = (ask + 1) % types.length;
question_text.text = `№${question}. Напиши ${types[answer]}, если ${types[ask]} - ${element[ask]}:`;
answer_button.onClick(() => {
if (element[answer].toLowerCase() == answer_input.value.toLowerCase()) {
question += 1;
answer_input.value = '';
newQuestion();
}
else {
question_text.text = `ответ введён неверно; правильный ответ при ${element[ask]} - ${element[answer]}. Отвечено верно: ${question-1}`;
answer_input.hide();
answer_button.hide();
start_test.show();
answer_input.value = '';
}
});
}
newQuestion();
});
}
else {
engine.createHeader('Новый тест')
engine.createText('название теста:')
const testName = engine.createInput.text();
engine.createText('автор теста:')
const testAuthor = engine.createInput.text();
engine.createText('названия столбцов через ; (пример: "символ элемента;название элемента;произношение элемента")');
const testTypes = engine.createInput.text();
engine.createText('столбцы через ; и без пробелов (пример: H;водород;аш)')
const testQuestions = document.createElement('textarea');
testQuestions.spellcheck = false
document.getElementById("main").appendChild(testQuestions);
engine.space();
const testCreate = engine.createButton('создать тест');
testCreate.onClick(() => {
const newParams = new URLSearchParams();
newParams.append('name', testName.value)
newParams.append('author', testAuthor.value)
const types = testTypes.value.split(';')
types.forEach(type => newParams.append('0', type));
let questionID = 1;
let questions = testQuestions.value.split('\n');
questions.forEach(question => {
const options = question.split(';')
console.log(options);
options.forEach(option => newParams.append(questionID.toString(), option));
questionID++;
});
newParams.append('length', questions.length)
document.location.search = newParams;
})
}