<! DOCTYPE html PUBLIC "-// W3C // dtd html 4.01 Transitional // EN" "http://www.w3.org/TR/html4/loose.dtd">
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = GB18030">
<Title> Insert title here </title>
<Script type = "text/javascript">
/*
* First load the form
* Generate a random number between 1 and
* Get button
* Obtain the value of text.
* When you click the button, use the text value to compare with the random number.
*
*/
Window. onload = function (){
Var num = Math. floor (Math. random () * 100 + 1 );
Var button = document. getElementById ("button ");
Var times = 0;
Button. onclick = function (){
Var text = document. getElementById ("inputText ");
Var value = text. value;
If (++ times> 3 ){
Alert ("You are not suitable for such games ");
Return;
}
If (isNaN (value )){
Alert ("You are not entering a number. Please enter a number! ");
} Else if (value <1 | value> 100 ){
Alert ("enter a number ranging from 1 ");
} Else if (value = num ){
Alert ("You guessed it! ")
} Else if (value> num ){
Alert ("big ");
} Else {
Alert ("small ");
}
Text. value = "";
}
}
</Script>
</Head>
<Body>
Enter a 1-100 INTEGER: <input type = "text" id = "inputText"> <input type = "button" id = "button" value = "Guess">
</Body>
</Html>
From Dai junjian's column