iceman023 Posted May 26, 2009 Share Posted May 26, 2009 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> Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 26, 2009 Share Posted May 26, 2009 And the issue you're having is...? By the way, there is a distinct difference between Java and JavaScript. You shouldn't use them interchangeably. Edit: you didn't close the brace "}" for the function. Quote Link to comment Share on other sites More sharing options...
iceman023 Posted May 26, 2009 Author Share Posted May 26, 2009 I added a bracket and it still doesnt work... I think im missing the part in the function to actually roll the dice. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 26, 2009 Share Posted May 26, 2009 "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; Quote Link to comment Share on other sites More sharing options...
Andy-H Posted May 26, 2009 Share Posted May 26, 2009 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"); } Quote Link to comment Share on other sites More sharing options...
iceman023 Posted May 26, 2009 Author Share Posted May 26, 2009 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> Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 26, 2009 Share Posted May 26, 2009 Aww.. is your copy and paste not working? Just remove the ending ) after the "+ 1". Quote Link to comment Share on other sites More sharing options...
iceman023 Posted May 26, 2009 Author Share Posted May 26, 2009 Nice thanks.. Step one completed! Now i have to add the 6 pictures of dice that need to appear from the button. How do i do this though? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.