| 123456789101112131415161718192021222324252627282930313233343536 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- </head>
- <body>
- <script>
- // 计算获胜率
- function WinRate(n){
- // 生成1-9之间的随机数
- var num1 = Math.floor(Math.random()*9)+1;
- var num2 = Math.floor(Math.random()*9)+1;
- var num3 = Math.floor(Math.random()*9)+1;
- console.log(num1,num2,num3);
- if(num1 == 8 || num2 == 8 || num3 == 8) {
- return true;
- }else{
- return false;
- }
- }
-
- var winCount = 0;
- var playCount = 10;
- for(var i = 0;i<playCount;i++){
- // 每次游戏都调用WinRate函数
- if(WinRate()){
- winCount++;
- }
- }
- console.log((winCount/playCount)*100 + "%");
- </script>
- </body>
- </html>
|