-
Notifications
You must be signed in to change notification settings - Fork 0
/
guessnumber.html
93 lines (93 loc) · 2.25 KB
/
guessnumber.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>GUESSNUMBER</title>
<style type="text/css">
.guessNumber{
width: 300px;
height: 300px;
margin: auto;
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
border: 1px solid #000;
}
.guessNumber h2{
text-align: center;
}
.guessNumber .guessC{
width: 250px;
margin: auto;
}
.guessNumber #numInput{
border: none;
outline: none;
border: 1px solid #000;
width: 237px;
height: 30px;
border-radius: 20px 20px 20px 20px;
text-indent: 15px;
}
.guessNumber #btnGuess{
border: none;
outline: none;
border: 1px solid #000;
width: 71px;
height: 31px;
border-radius: 0 0 30px 30px;
text-indent: 15px;
left: 84px;
right: 2px;
position: relative;
}
</style>
</head>
<body>
<hr align="top" size="6" color="crimson" />
<div class="guessNumber">
<h2 class="title">GUESSNUMBER</h2>
<div class="guessC">
<input id="numInput" type="number" placeholder="1-10 six chances" />
<input id="btnGuess" onclick="guess()" type="button" value="Guess"/>
</div>
<div class="tip">
<p>chance:<span id="chance">6</span></p>
<p>history:</p>
<p id="tipText"></p>
</div>
</div>
<script type="text/javascript">
var targetNum=parseInt(Math.random()*11);
console.log(targetNum);
var guessTimes=6;
var oNuminput=document.getElementById("numInput");
var oBtnguess=document.getElementById("btnGuess");
var oTiptext=document.getElementById("tipText");
var oChance=document.getElementById("chance");
function guess(){
if(oNuminput.value>targetNum){
oTiptext.innerHTML+="<br />smaller";
oNuminput.value="";
oNuminput.focus();
guessTimes-=1;
oChance.innerHTML=guessTimes;
}
else if(oNuminput.value<targetNum){
oTiptext.innerHTML+="<br />bigger";
oNuminput.value="";
oNuminput.focus();
guessTimes-=1;
oChance.innerHTML=guessTimes;
}
else if(oNuminput=targetNum){
oTiptext.innerHTML+="<br />CORRECT!!!";
oNuminput.value="";
oNuminput.focus();
}
}
</script>
</body>
</html>