I am trying this simple JavaScript project for my Bootcamp pre work and it suggested making a new button and I decided to try and make a random button out of the buttons I had already created so that when you clicked it, it would run one of the scripts for the buttons that I have already defined. I have been working on this for a few hours and I just can't seem to get it or find another example of what I'm trying to do. Any help would be much appreciated!!!
document.getElementById("button1").addEventListener("click", function () {
document.getElementById("box").style.height = "300px"
document.getElementById("box").style.width = "300px"
});
document.getElementById("button2").addEventListener("click", function () {
document.getElementById("box").style.height = "50px"
document.getElementById("box").style.width = "50px"
});
document.getElementById("button3").addEventListener("click", function () {
document.getElementById("box").style.backgroundColor = "blue"
});
document.getElementById("button4").addEventListener("click", function () {
document.getElementById("box").style.opacity = "0.2"
});
document.getElementById("button5").addEventListener("click", function () {
document.getElementById("box").style = "height:150px; width:150px; background-color:orange; margin:25px"
});
let btnList = ["#button1", "#button2", "#button3", "#button4", "#button5"];
const randomBtn = document.getElementsByClassName('rand');
randomBtn.addEventListener("click", function () {
Math.floor(Math.random() * randomBtn.length)
})
<html>
<head>
<title>Jiggle Into JavaScript</title>
<!-- <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script> -->
</head>
<body onload="printBtn();">
<p>Press the buttons to change the box!</p>
<div id="box" style="height:150px; width:150px; background-color:orange; margin:25px"></div>
<button class="rand" id="button1">Grow</button>
<button class="rand" id="button2">Shrink</button>
<button class="rand" id="button3">Blue</button>
<button class="rand" id="button4">Fade</button>
<button class="rand" id="button5">Reset</button>
<button class="rand">Random</button>
<script type="text/javascript" src="javascript.js"></script>
</body>
</html>