Jump to content

Rolling Dice game.. ASAP


iceman023

Recommended Posts

I need help creating an html file that runs java.. The script has to have two dice and once you click on the button, 2 dice appear.. If they are the same dice, text should appear underneath saying "You complete the game" or "you again"

 

 

P.S purpose of the game is to get both dice the same and i have 6 pics called d1.png, d2.png, ect...

 

Someone please help

 

 

This is what i have so far

<html>
<head>
<script language="javascript">
<!--
function rollthedice() {
	var d1,d2;
	d1 = Math.floor((Math.random()*6) + 1);
	d2 = Math.floor((Math.random()*6) + 1);


	if(d1 == d2)
		{
			document.write("You Rolled a Double");
		}
		else if
			{
				document.write("Try again");
			}

-->
</script>


<title>Untitled Document</title>
</head>
<body>
<form name="form1" method="post" action="">
  <center>
    <p>
      <input type="submit" value="Roll for a Double" onClick="rollthedice()">
    </p>
  </center>
  </form>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/159644-rolling-dice-game-asap/
Share on other sites

 if(d1 == d2)
 		{
 			document.write("You Rolled a Double");
 		}
 		else if
 			{
 				document.write("Try again");
 			}


 

Shouldn't that be:

 

 if(d1 == d2)
 		{
 			document.write("You Rolled a Double");
 		}
 		else
 			{
 				document.write("Try again");
 			}

 

ok so now i have this

 

 

<html>
<head>
<script language="javascript">
<!--
function rollthedice() {
	var d1,d2;
	d1 = Math.floor(Math.random()*6) + 1);
	d2 = Math.floor(Math.random()*6) + 1);


	if(d1 == d2)
		{
			document.write("You Rolled a Double");
		}
		else
			{
				document.write("Try again");
			}}

-->
</script>


<title>Untitled Document</title>
</head>
<body>
<form name="form1" method="post" action="">
  <center>
    <p>
      <input type="submit" value="Roll for a Double" onClick="rollthedice()">
    </p>
  </center>
  </form>
</body>
</html>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.