There is a code:
var arr = new Array(0, 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); var RandElement = Math.floor(Math.random() * arr.length); var link = ''; console.log(RandElement); And swith :
switch (RandElement) { case 0: var SummDok = document.getElementById('left_block_menu'), SummSumm='текст'; SummDok.innerHTML = SummSumm; break; case 1: var SummDok = document.getElementById('left_block_menu'), SummSumm='текст'; SummDok.innerHTML = SummSumm; break; ... And everything is done perfectly, the random number is determined, and depending on it, one or another text is issued. But there is another button, when you click on that, the number should increase by one and produce the result without refreshing the page (taking into account the changed number, that is, if there was case3 , then after pressing the text should be taken from case4 . I only did it :
document.querySelector('.but_rek_left_block3').onclick = function() { RandElement++; if (RandElement == 31) { RandElement = 0; } console.log(RandElement); switch (RandElement) { case 0: var SummDok = document.getElementById('left_block_menu'), SummSumm='текст'; SummDok.innerHTML = SummSumm; break; case 1: var SummDok = document.getElementById('left_block_menu'), SummSumm='текст'; SummDok.innerHTML = SummSumm; break; ... But this is an increase in the code, since both are swith by 30, and in the button too .. can there be a way to shorten it all?
Here is the div (button):
<div class="but_rek_left_block3" id="but_rek_left_block3"> <div><spans>Пропустить</spans></div> </div>