jeudi 13 février 2020

How to add website links to a random image generator

i have this code and want to know how to add website links to the images, once the random image is generated i want the image can be clicked to go to a predetermined list of websites, it's a really beginner question since i don't really understand javascript functions.

Thank you.

<html>
<head>
<script type="text/javascript">
//preload the six images first
var face0=new Image()
face0.src="d1.gif"
var face1=new Image()
face1.src="d2.gif"
var face2=new Image()
face2.src="d3.gif"
var face3=new Image()
face3.src="d4.gif"
var face4=new Image()
face4.src="d5.gif"
var face5=new Image()
face5.src="d6.gif"
</script>
</head>
<body>
<img src="d1.gif" name="mydice">
<form>
<input type="button" value="Throw dice!" onClick="throwdice()">
</form>
<script>
function throwdice(){
    //create a random integer between 0 and 5
    var randomdice=Math.round(Math.random()*5)
    document.images["mydice"].src=eval("face"+randomdice+".src")
}
</script>
</body>
</html>



Aucun commentaire:

Enregistrer un commentaire