js实现1-10猜数字
唯有热爱可抵岁月漫长
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>猜数字随机数1-10</title>
<script>
function getRandom(min,max){
return Math.floor(Math.random() * (max - min + 1)) + min;
}
var num = getRandom(1,10);
var postnum = prompt('猜数字,1-10');
while (postnum != num){
//隐藏的代表只会提示错了 不会提示大小
// alert('猜错了');
// var postnum = prompt('猜数字,1-10');
if(postnum > num){
alert('大了');
var postnum = prompt('猜数字,1-10');
}
else{
alert('小了')
var postnum = prompt('猜数字,1-10');
}
}
document.write('恭喜您,猜对了');
</script>
</head>
<body>
</body>
</html>