<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<script type="text/javascript">
var x=parseInt(Math.random()*10);
var low=0,high=9;
var count=0;
console.log(x);
while (low<=high){
count ++;
var mid=parseInt((low+high)/2);
console.log("第"+count+"次数猜"+mid);

if (x<mid) {
high=mid-1;
}
else if(x>mid){
low=mid+1;
}
else {
console.log("恭喜猜对了!");
break;
}
}
</script>
</body>
</html>

相关文章:

  • 2021-11-30
  • 2021-12-03
  • 2022-12-23
  • 2021-04-12
  • 2021-10-15
  • 2021-11-30
  • 2021-06-21
  • 2021-07-28
猜你喜欢
  • 2021-11-30
  • 2021-06-09
  • 2021-09-16
  • 2021-08-13
  • 2022-12-23
  • 2021-04-19
相关资源
相似解决方案