JS guess the number of small games simple implementation code

Source: Internet
Author: User
Tags min rand
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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.