JSFiddle - React, Tailwind, and code Playground
JavaScript
function es() {
if(!confirm('Начать?')) return;
alert("Задумайте любое число.");
x = 0;
var today = new Date();
sec = 0;
for (i = 1; i <= 5; i++) {
sec = today.getSeconds();
rand1 = 31;
while (rand1 > 30) {
rand1 = Math.random() * sec * 100;
rand1 = Math.ceil(rand1);
}
rand2 = Math.random();
if (rand2 > 0.5) {
mes = "прибавьте ";
mes1 = "";
y = rand1;
} else {
mes = "вычтите ";
mes1 = " от полученного числа";
y = -rand1;
}
x1 = x
x = x + y
if (x < 0) {
mes = "прибавьте к нему ";
mes1 = "";
x = x1 + rand1;
}
alert("Теперь, " + mes + rand1 + mes1 + ". ");
}
alert("Теперь вычтите число, которое Вы задумали.");
alert("У Вас получилось " + x + " , не так ли ?");
}
es();