Im trying to make a simple game where choice is an illusion. You have 4 buttons to pick from, north, west east and south, and onclick I want each button to generate a random number using math.random, then using window.location to take them to that numbered page in the same click.
i.e. there are 100 html pages labeled 1.html, 2.html, 3.html, all the way up to 100.html, you start on page 1.html, click north, the randomly generated number takes you to 23.html, click again, 79.html, click again, 3.html, and so on.
I know how to use window.location to take you to a set page, and I know how to do math.random to choose a number between 1-100, but I dont know how to put these two elements together to do what I want.
<html>
<head>
<script>
function beginner()
{
document.getElementById("demo1").innerHTML=(Math.floor(Math.random()*100)+1);
}
</script>
</head>
<body>
<div id="header" style="clear: both; margin-bottom: 25px;">
pick a direction to go
</div>
<div id="nav" style="float: left; ">
<center>
<input type="button" id="north" value="north" onclick="window.location='demo1';" /> <br />
<input type="button" id="west" value="west" onclick="randompage2();" />
<input type="button" id="east" value="east" onclick="randompage3();" /> <br />
<input type="button" id="south" value="south" onclick="randompage4();" />
</center>
</div>
</body>
</html>
Aucun commentaire:
Enregistrer un commentaire