so I have linked two images in HTML from the folder: images/ however in javascript I’m trying to make these images for the dice to randomly change after every time refreshes.
I’m not sure why isn’t working
here is the HTML code
<div class="container">
<h1>Refresh Me</h1>
<div class="dice">
<p>Player 1</p>
<img class="img1" src="images/dice6.png">
</div>
<div class="dice">
<p>Player 2</p>
<img class="img2" src="images/dice6.png">
</div>
</div>
and here is the js code
imgArray = [
"dice1.png",
"dice2.png",
"dice3.png",
"dice4.png",
"dice5.png",
"dice6.png"
]
function images(){
// the random images
var randomNumber1 = Math.floor(Math.random() * imgArray.length);
// get images at randomNumber1
selectedImages = imgArray[randomNumber1]
// display the images()
document.getElementByClassName("img1").src = "./images/${selectedImages}"
}
Note: I’m a new learner still trying to understand javascript. thank you for your humble reply and help. and if isn’t too much to make the explanation simple so I could follow.