Advertisement
metalx1000

Monty Hall Problem

May 8th, 2013
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <html>
  2.     <head>
  3.         <script>
  4.             function go(){
  5.                 st=0; //count the number of wins with staying
  6.                 sw=0; //count the number of wins with switching
  7.  
  8.                 door = new Array("Win","Lose","Lose"); //Create 3 Doors
  9.  
  10.    
  11.                 document.getElementById('output').innerHTML="Stay Wins -- Switching Wins<hr>";
  12.    
  13.                 for(i=0;i<100;i++){
  14.                     output=document.getElementById('output').innerHTML;
  15.                     x=Math.floor(Math.random() * 3); //pick a random door
  16.    
  17.                     p=door[x];
  18.  
  19.                     if(x==1){
  20.                         s="lose";
  21.                         st++;
  22.                     }else{
  23.                         s="win";
  24.                         sw++;
  25.                     }
  26.                     document.getElementById('output').innerHTML=output + p + " -- " + s + "<br>\n";
  27.                 };
  28.  
  29.                 m1="Staying will win " + st + " of the time.\n";
  30.                 m2="Switching will win " + sw + " of the time.\n";
  31.                 document.getElementById('output').innerHTML=output + "<hr>" + m1 + m2;
  32.             }
  33.         </script>
  34.     </head>
  35.     <body onload="go()" >
  36.         <div id="output"></div>
  37.     </body>
  38. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement