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> Link to comment https://forums.phpfreaks.com/topic/159644-rolling-dice-game-asap/ 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. Link to comment https://forums.phpfreaks.com/topic/159644-rolling-dice-game-asap/#findComment-842031 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. Link to comment https://forums.phpfreaks.com/topic/159644-rolling-dice-game-asap/#findComment-842032 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; Link to comment https://forums.phpfreaks.com/topic/159644-rolling-dice-game-asap/#findComment-842036 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"); } Link to comment https://forums.phpfreaks.com/topic/159644-rolling-dice-game-asap/#findComment-842037 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> Link to comment https://forums.phpfreaks.com/topic/159644-rolling-dice-game-asap/#findComment-842039 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". Link to comment https://forums.phpfreaks.com/topic/159644-rolling-dice-game-asap/#findComment-842041 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? Link to comment https://forums.phpfreaks.com/topic/159644-rolling-dice-game-asap/#findComment-842042 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.