Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <script>
- function roll(){
- rolls=document.getElementById('rolls').value;
- dice_num=document.getElementById('dice_num').value;
- win=0;
- lose=0;
- green=0;
- red=0;
- die=0;
- dice=new Array("red","yellow","yellow","green","green","green");
- document.getElementById('output').innerHTML="";
- for(i=rolls;i>0;i--){
- for(y=dice_num;y > 0;y--){
- r=Math.floor(Math.random()*6);
- die=dice[r];
- document.getElementById('output').innerHTML+=die + ", ";
- if(die == "green"){
- green++;
- }
- else if(die == "red"){
- red++;
- }
- }
- document.getElementById('output').innerHTML+="<br>";
- if( green == 0 && red > 0 ){
- lose++;
- }
- else{
- win++;
- }
- red=0;
- green=0;
- }
- document.getElementById('output').innerHTML+="<br>================<br>";
- document.getElementById('output').innerHTML+="Wins: " + win + "<br>";
- document.getElementById('output').innerHTML+="Loses: " + lose + "<br>";
- window.scrollTo(0, document.body.scrollHeight);
- }
- </script>
- </head>
- <body>
- <div id="output"></div>
- <div id="input">
- Enter Number of Rolls:<input type="text" id="rolls"><br>
- Enter Number of Dice:<input type="text" id="dice_num"><br>
- <button onclick="roll()">Run Simulation</button>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement