This repository was archived by the owner on Sep 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
93 lines (75 loc) · 2.96 KB
/
Copy pathscript.js
File metadata and controls
93 lines (75 loc) · 2.96 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
(function a() {
const xDefaultValues = [-2, -1.5, -1, -0.5, 0, 0.5, 1, 1.5, 2];
let errorsArea = document.getElementById("errors-area");
let submitButton = document.getElementById("submit-button");
let xCheckBoxes = document.querySelectorAll("input[name='x']");
let yText = document.getElementById("y");
let rText = document.getElementById("r");
submitButton.addEventListener("click", onSubmit);
let errorsText = "";
function onSubmit(event) {
if (!check()) {
event.preventDefault();
errorsArea.innerText = errorsText;
if (errorsText != null)
errorsArea.classList.remove("invisible");
else
errorsArea.classList.add("invisible");
errorsText = "";
}
}
function check() {
//checking x
let selected = null;
for (let i = 0; i < xCheckBoxes.length; i++) {
if (xCheckBoxes[i].checked) {
if (selected) {
errorsText += "Следует выбрать\n одно значение X\n";
}
if (xDefaultValues.indexOf(+xCheckBoxes[i].value) === -1) {
errorsText += "Уважаемые хакеры! Не стоит ломать это,\n оно прекрасно сломается " +
"и без Вашего участия.\n Спасибо!\n";
}
selected = xCheckBoxes[i].value;
}
}
if (!selected) {
errorsText += "Следует выбрать X\n";
}
//checking y
yText.value = yText.value.trim();
if (yText.value.length === 0) {
errorsText += "Поле Y обязательно\n";
}
if (yText.value.length >= 10) {
errorsText += "Значение координаты \nY некорректно\n";
}
let yTextValue = yText.value.replace(',', '.');
if (isNaN(yTextValue)) {
errorsText += "В поле Y следует\n ввести число\n";
}
let val = +yText.value;
if (val <= -5 || val >= 3) {
errorsText += 'Y должен лежать в (-5 ; 3)\n';
}
//checking r
rText.value = rText.value.trim();
if (rText.value.length === 0) {
errorsText += "Поле R обязательно\n";
}
if (rText.value.length >= 10) {
errorsText += "Значение радиуса\n R некорректно\n";
}
let rTextValue = rText.value.replace(',', '.');
if (isNaN(rTextValue)) {
errorsText += "В поле R следует\n ввести число\n";
}
let v = +rText.value;
if (v <= 1 || v >= 4) {
errorsText += 'R должен лежать в (1 ; 4)';
}
if (errorsText !== "")
return false;
return true;
}
})();