Advertisement
RokiAdhytama

Roll Die - Chapter 11

Jul 3rd, 2022
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. <html xmlns = "http://www.w3.org/1999/xhtml">
  2. <head>
  3. <title>Roll a Six-Sided Die 6000 Times</title>
  4.  
  5. <script type = "text/javascript">
  6. <!--
  7. var face, frequency = [ , 0, 0, 0, 0, 0, 0 ];
  8.  
  9. // summarize results
  10. for ( var roll = 1; roll <= 6000; ++roll ) {
  11. face = Math.floor( 1 + Math.random() * 6 );
  12. ++frequency[ face ];
  13. }
  14.  
  15. document.writeln( "<table border = \"1\"" +
  16. "width = \"100%\">" );
  17. document.writeln( "<thead><th width = \"100\"" +
  18. " align = \"left\">Face<th align = \"left\">" +
  19. "Frequency</th></thead><tbody>" );
  20.  
  21. for ( face = 1; face < frequency.length; ++face )
  22. document.writeln( "<tr><td>" + face + "</td><td>" +
  23. frequency[ face ] + "</td></tr>" );
  24.  
  25. document.writeln( "</tbody></table>" );
  26. // -->
  27. </script>
  28.  
  29. </head>
  30. <body>
  31. <p>Click Refresh (or Reload) to run the script again</p>
  32. </body>
  33. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement