<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <script> var m=parseInt(Math.random()*100); var count=0; for(;;){ count=count+1; var num1=parseInt(prompt("请输入一个数字:")); if(num1==m){ alert("恭喜你,猜对了"); break; }else if(num1>m){ alert("大了"); }else if(num1<m){ alert("小了"); } if(count>5){ alert("次数已经用完,请从新开始"); } } console.log(count); </script> </body> </html>
原文:https://www.cnblogs.com/qurui1998/p/10492273.html