Answer the question
In order to leave comments, you need to log in
How to implement randomize a random number and display a block under this number?
Hello!
I need to implement the following: the system randomizes a random number in a given range (let it be from 1 to 5), the user presses the button, the system displays a block for him under the previously randomized number. The text block is rendered using HTLM.
Answer the question
In order to leave comments, you need to log in
If I understand you correctly, then it is very simple to do this in
HTML:
<a onclick="randomDiv()">click</a>
<div id="random1" style="display: none;">Random div 1</div>
<div id="random2" style="display: none;">Random div 2</div>
<div id="random3" style="display: none;">Random div 3</div>
<div id="random4" style="display: none;">Random div 4</div>
<div id="random5" style="display: none;">Random div 5</div>
function randomDiv(){
let randNum = getRandomInRange(1, 5);
document.getElementById('random'+randNum).style.display = "block";
}
function getRandomInRange(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question