This article introduced the JS Guess Digital Games Simple implementation code, very fun game Oh, you can see whether your IQ is staggering amount
copy code code as follows:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns= "http://www.w3.org/1999/xhtml" >
<head>
<meta http-equiv= "Content-type" content= "text/html"; charset=gb2312 "/>
<title> Simple Computer </title>
</head>
<body>
<input type= "button" id= "result" name= "result" onclick= "Checknum ()" value= "Enter digital game 、、、、、" >
<script>
//Get random number
function Getrandomnum (Min,max)
{
var Range = max-min;
var Rand = Math.random ();
return (Min + math.round (Rand * Range));
}
//Get text box contents
function Checknum () {
var num = getrandomnum (1,100);
alert ("Dnhgn");
var i;
for (i=1;i<=10;i++) {
var nums=prompt ("Guess 1 to 100 number, you only have 10 chance oh, come on Oh 、、、、、", "");
if (i==1) {
if (nums==num) {
alert ("Congratulations, you're too smart");
break;
}else{
if (nums<num) {
document.write ("You are already the first" + i + "The second input, the number somewhat small <br>");
}else{
document.write ("You are already the first" + i + "The second input, the number is somewhat large <br>");
}
}
}
if (i>1&&i<=10) {
if (nums==num) {
Alert ("Congratulations on the right answer");
break;
}else{
if (nums<num) {
document.write ("You are already the first" + i + "The second input, the number somewhat small <br>");
}else{
document.write ("You are already the first" + i + "The second input, the number is somewhat large <br>");
}
}
}
if (i==10) {
if (nums!=num) {
document.write ("You have no chance, it's a pity!") ");
return false;
}
}
}
}
</script>
</body>
</html>