Here is a problem I've encountered. This code selects a random element from an array to hide/show a div by toggling it. The issue is that I want it to always open a new one while hiding the previous one with the same button click. Currently, it shows a new element but fails to hide the previous one.
It doesn't have to be randomly selected, but it must consistently open a new element while hiding the others. I'm a bit stuck on this and could use some guidance.
If you have any hints or suggestions, I would greatly appreciate your input. Thank you for your attention!
document.getElementById("rojo").addEventListener("click", show);
var secret = ["h-ma-1","h-ma-2","h-ma-3" ];
var s = secret[RndInt(0, 2)];
function RndInt(min, max) {
return Math.floor(Math.random() * (max - min+ 1) ) + min;}
function show (){
for ( var i=0 ; i<=0 ; i++ ){
if
(document.getElementById(s).style.display == "block")
{
document.getElementById(s).style.display = "none";
}
else
{
document.getElementById(s).style.display = "block";
}
}
}