<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
var truenum = function(max,min){
return Math.floor(Math.random() * (max - min) + min);
}
var num1 = truenum(1,10);
document.write(truenum(1,10));
var flag = false
while (!flag){
var n = prompt("请输入1——10之间的数字")
if (n <num1){
alert("数字太小")
flag = false;
}else if (n > num1){
alert("数字太大")
flag = false;
}else if (n = num1){
alert("正确,结束程序")
flag = true;
}
}
</script>
</body>
</html>
|