fork download
  1. <html>
  2. <head>
  3. <title>Beat-That!</title>
  4. <style type = "text/css">
  5. table { width: 15em }
  6. th { text-align: left }
  7. </style>
  8. <script type = "text/javascript">
  9.  
  10. var round;
  11. var player1 = [ ,1,1,1,1,1];
  12. var player2 = [ ,1,1,1,1,1];
  13. var total1=0;
  14. var total2=0;
  15. var winner1;
  16. var winner2;
  17. total1=total1*player1;
  18. total2=total2*player2;
  19. function play()
  20. {
  21. for ( var roll = 1; roll <= 6; ++roll )
  22. {
  23. round = Math.floor( 1 + Math.random() * 5 );
  24. ++player1[ round ];
  25. }
  26.  
  27. if (total1>total2)
  28. {
  29. winner1 = 1;
  30. winner2 = 0;
  31. }
  32. else{
  33. winner1= 0;
  34. winner2 = 1;
  35. }
  36.  
  37. for ( var roll = 1; roll <= 6; ++roll )
  38. {
  39. round = Math.floor( 1 + Math.random() * 5 );
  40. ++player2[ round ];
  41. }
  42.  
  43.  
  44.  
  45. document.writeln("<table border = \"1\"><thead>");
  46. document.writeln("<th>Round</th>" +
  47. "<th>Player 1</th>" + "<th>Player 2</th></thead><tbody>");
  48.  
  49. for ( round = 1; round < player1.length; ++round )
  50. document.writeln( "<tr><td>" + round + "</td><td>" +
  51. player1[ round ] + "</td><td>" + player2[ round ] + "</td></tr>");
  52. document.writeln("<tr><td>Total</td><td>"+total1+"</td><td>"+total2+"</td></tr>")
  53.  
  54.  
  55. document.writeln("<tr><td>Winner</td><td>"+winner1+"</td><td>"+winner2+"</td></tr>")
  56. document.writeln("</tbody></table>");
  57. }
  58. </script>
  59. </head>
  60. <body>
  61. <form action="">
  62. <p>Click the button to roll<br />
  63. <input type="button" value="Roll Dice" onclick="play()"
  64. </form>
  65. <p>Click Refresh (or Reload) to run the script again</p>
  66. </body>
  67. </html>
  68.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty