index.html
<!DOCTYPE html> <html lang="ja"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>å²åãè¨å®ããã©ã³ãã </title> <style> img{ vertical-align: bottom; max-width: 100%; } .box{ width: 240px; margin: 50px auto 0; } #btn{ padding: 10px; } </style> </head> <body> <div class="box"> <h1>ä»æ¥ã®éå¢å ã</h1> <p id="loto"><img src="img/kuji.png" alt=""></p> <button id="btn" onclick="kuji();">ãã¿ãããå¼ã</button> </div> <script> function kuji(){ //1~100ã¾ã§ã®ã©ã³ãã ãä½æ let num = Math.ceil(Math.random()*100); console.log(num); let daikichi = 40 //大åã®åºã確ç40% let chukichi = 60 //ä¸åã®åºã確çã¯20%ã ãã©ã大åã®åºã確çã¨åç®ãã let kichi = 95//åã®åºã確çã¯35%ã ãã©å¤§åãä¸åã¨åç®ãã //å¶ã®åºã確çã¯ãã以å¤ãªã®ã§å¤æ°ã®ç»é²ã¯å¿ è¦ãªã if(num <= daikichi){ //1~15ãåºãã大å var raito = 0; }else if(num <= chukichi){ //16~40ãåºããä¸å var raito = 1; }else if(num <= kichi){ //41~90ãåºããå var raito = 2; }else{ //ãã以å¤ãåºããå¶ var raito = 3; } console.log(raito); document.querySelector('#loto').innerHTML = '<img src="img/'+raito+'.png" alt="">' } </script> </body> </html>