综合题5_编程题9.html 881 B

123456789101112131415161718192021222324252627282930313233343536
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. </head>
  8. <body>
  9. <script>
  10. // 0.999999
  11. // 0.000000001
  12. // 1-9 0-8
  13. function game(){
  14. var num1 = Math.floor(Math.random()*9)+1;
  15. var num2 = Math.floor(Math.random()*9)+1;
  16. var num3 = Math.floor(Math.random()*9)+1;
  17. if(num1 == 8 || num2 == 8 || num3 == 8){
  18. console.log(num1,num2,num3);
  19. return true
  20. }else{
  21. return false
  22. }
  23. }
  24. var win = 0;//赢的次数
  25. for(var i = 0;i<10;i++){
  26. if(game()){
  27. win++;
  28. }
  29. }
  30. console.log((win/10)*100 + "%");
  31. </script>
  32. </body>
  33. </html>