// Web games: guessing
<! 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>
<Style type = "text/css">
Input {
Width: 150px;
}
</Style>
<Script type = "text/javascript">
Window. onload = function (){
// Obtain four buttons and two input boxes
Var stone = document. getElementById ("stone ");
Var cut = document. getElementById ("cut ");
Var cloth = document. getElementById ("cloth ");
Var mine = document. getElementById ("mine ");
Var guess = document. getElementById ("guess ");
Var computer = document. getElementById ("computer ");
// When you click a button, assign the value of the button to the value of mine.
Function click (){
Mine. value = this. value;
}
Stone. onclick = click;
Cut. onclick = click;
Cloth. onclick = click;
// Generate a random number. 1 represents the stone, and 2 represents the scissors and 3 cloths.
Guess. onclick = function (){
Var num = Math. floor (Math. random () * 3 + 1 );
If (num = 1)
Computer. value = "Stone ";
Else if (num = 2)
Computer. value = "Scissors ";
Else if (num = 3)
Computer. value = "cloth ";
Var mineValue = mine. value;
Var computerValue = computer. value;
If (mineValue = computerValue)
Alert ("Draw ");
Else if (mineValue = "")
Alert (computerValue = "Scissors "? "Win": "lose ");
Else if (mineValue = "Scissors ")
Alert (computerValue = "cloth "? "Win": "lose ");
Else if (mineValue = "cloth ")
Alert (computerValue = "Stone "? "Win": "lose ");
Mine. value = "";
Computer. value = "";
}
}
</Script>
</Head>
<Body>
<Input type = "button" value = "stone" id = "stone">
<Input type = "button" value = "Scissors" id = "cut">
<Input type = "button" value = "cloth" id = "cloth"> <br>
<Input id = "mine"> <br>
<Input type = "button" value = "guess" id = "guess"> <br>
<Input id = "computer">
</Body>
</Html>
From Dai junjian's column