How to make my script wait for new text from the button and enter it into the field, rather than take it in a loop.
<script> //server side function change() { var rand = Math.round(Math.random() * (100 - 10)) + 10; var rand1 = Math.round(Math.random() * (100 - 10)) + 10; document.querySelector('.Button.Button--negative.Button--size-m.Button--wide.Button--overflow').textContent="Убрать кнопки | " + rand + " + " + rand1 + " = ?"; } (function loop() { var rand2 = Math.round(Math.random() * (3000 - 1000)) + 1000; setTimeout(function() { change(); loop(); }, rand2); }()); //server side //client side function matem() { var ans = document.querySelector('.Button').textContent; var ots1 = ans.split(' =')[0]; var otv = eval(ots1.split('| ')[1]); document.querySelector('.ans').value=otv } (function loop() { var rand = Math.round(Math.random() * (2500 - 500)) + 2500; setTimeout(function() { matem(); loop(); }, rand); }()); //client side </script>
<div class="Keyboard__container"><div class="Keyboard__row"><div class="Keyboard__button" style="width: calc(100% - 10px);"><button class="Button Button--negative Button--size-m Button--wide Button--overflow"></button><br><textarea class="ans"></textarea></div></div><div