<script>
function doublekill() {
var array = new Array("大象","秘密","茶袋","鞋子","睡袋","头发","订书机","披萨","床","轮子","行李箱","胡须","叶子",
"气球","黄色","烟花","翅膀","海星","火烈鸟","城堡","矛","出租车","摩托车","苹果","相机","扑克","羊毛衫","话筒",
"花生酱","鼓","风车","钻头","垃圾箱","塑料","柔软","监狱","水槽","铝","鲨鱼","木炭","男管家","雨靴","镜子","洞",
"薯条店","雕像","潜望镜","按钮","斧头","长号");
var select_word = [];
//利用Math.random随机生成
//随机值公式:var r = parseInt(Math.random() * (max - min + 1) + min)
// ——》在任意范围内生成min-max生成随机数
var reds=[];
//只要reds的元素个数<2就要继续循环
while(reds.length<2){
//在1~50之间生成随机整数r
var r=parseInt(
Math.random()*50+1);
//遍历reds中每个元素
//通过i,模拟2个数且不能重复
for(var i=0;i<reds.length;i++){
//如果r等于当前元素
if(r==reds[i])
break;//就退出循环
}
//如果i等于reds的元素个数,保险句
//默认,i=0,永远成立
//所以当if判断成立,跳出for循环,继续在while中执行
//i 和 数组长度永远相等。
if(i==reds.length){
reds.push(r);//将r压入reds
}
}
//将reds按数字升序排列
function cmp(a,b){return a-b;}
reds.sort(cmp);
console.log('print reds: ' + reds);
alert("抽词结果:"+array[reds[0]]+" "+array[reds[1]]);
}
</script>
<h1>抽词准备黄脑训练~</h1>
<input type="button" value="今日抽词!" onclick="doublekill()" style="width:50%,height:50px">
</body>
</html>