-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
65 lines (57 loc) · 1.74 KB
/
script.js
File metadata and controls
65 lines (57 loc) · 1.74 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
var max_value = 10;
var operand1 = 0, operand2 = 0, result = 0;
var flag = 0;
var sign = "+";
var input = "";
// Вибір арифметичної операції
function set_sign(x) {
sign = x;
return true;
}
// Генерація першого операнда
function f_operand() {
return Math.floor(Math.random() * max_value);
}
// Генерація другого операнда
function s_operand() {
if (sign === "+") {
return Math.floor(Math.random() * (max_value - operand1));
} else if (sign === "-") {
return Math.floor(Math.random() * operand1);
} else if (sign === "*") {
return Math.floor(Math.random() * 10);
}
}
// Перевірка введеного результату
function input_sign(x) {
if (x == 10) {
let correctResult;
if (sign === "+") {
correctResult = operand1 + operand2;
} else if (sign === "-") {
correctResult = operand1 - operand2;
} else if (sign === "*") {
correctResult = operand1 * operand2;
}
if (parseInt(input) === correctResult) {
document.forms["test"].r0.value = "Вірно!";
} else {
document.forms["test"].r0.value = "Спробуй ще!";
input = "";
}
return true;
}
input += x;
document.forms["test"].result.value = input;
return true;
}
// Генерація нового завдання
function main_calc() {
operand1 = f_operand();
operand2 = s_operand();
document.forms["test"]["op1"].value = operand1;
document.forms["test"]["op2"].value = operand2;
document.forms["test"]["s_sign"].value = sign;
document.forms["test"]["r0"].value = "???";
input = "";
}