document.write("<input type='button' onclick='Guess()' value='提交'>")//按钮
function Guess() {
var inputVal=document.getElementById("inval").value //获取文本框的值
var curRand=parseInt(100*Math.random()) //获取随机数
if(!isNum(inputVal))
{
alert("不是数字,请重新输入")
return
}
if(inputVal){
if(inputVal>curRand){
alert("胜利")
} else if (inputVal<curRand){
alert("输了")
} else {
alert("平局")
}
}
}
//判断是否是数字,true表示是数字
function isNum(value) {
return !isNaN(value)
}
1楼思路是正确的
var num = Math.round((1+99*Math.random()))min = 1
max = 100
input =1
do{
if(input >max || input <min){
alert('有无搞错啊')
}else{
if(input > num){
max = input
} else if(input < num){
min = input
}
}
input = parseInt(prompt(min+"--"+ max,""))
}while(input!=num)
alert('对了'+input+" "+num)