Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <script>
- function go(){
- st=0; //count the number of wins with staying
- sw=0; //count the number of wins with switching
- door = new Array("Win","Lose","Lose"); //Create 3 Doors
- document.getElementById('output').innerHTML="Stay Wins -- Switching Wins<hr>";
- for(i=0;i<100;i++){
- output=document.getElementById('output').innerHTML;
- x=Math.floor(Math.random() * 3); //pick a random door
- p=door[x];
- if(x==1){
- s="lose";
- st++;
- }else{
- s="win";
- sw++;
- }
- document.getElementById('output').innerHTML=output + p + " -- " + s + "<br>\n";
- };
- m1="Staying will win " + st + " of the time.\n";
- m2="Switching will win " + sw + " of the time.\n";
- document.getElementById('output').innerHTML=output + "<hr>" + m1 + m2;
- }
- </script>
- </head>
- <body onload="go()" >
- <div id="output"></div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement