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
Share on other sites

"it still doesnt work" doesn't tell us who are trying to help anything. Please be specific.

 

I believe your logic is off. Try these two lines instead -

      d1 = Math.floor(Math.random()*6) + 1;
      d2 = Math.floor(Math.random()*6) + 1;

Link to comment
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");
 			}

 

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.