-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathguessnumber.html
54 lines (47 loc) · 1.22 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
<script src="bradapis.js"></script>
<script>
let answer = createAnswer(3);
//console.log(answer);
let log = '';
let times = 0;
function doGuess(){
times++;
let guessElement = document.getElementById('guess');
let guess = guessElement.value;
let result = checkAB(answer, guess);
log += times + "." + guess + " => " + result + "<br>";
document.getElementById('log').innerHTML = log;
if (result == 3 + 'A0B'){
alert('WINNER!');
reset();
}else if (times == 10){
alert('Loser: answer is ' + answer);
reset();
}else{
alert(result);
}
guessElement.value = '';
guessElement.focus();
}
function reset(){
if (!confirm('Reset?')) return;
times = 0;
answer = createAnswer(3);
log = '';
document.getElementById('log').innerHTML = log;
document.getElementById('guess').value = '';
document.getElementById('guess').focus();
}
</script>
<h1>Guess Number Game</h1>
<hr>
<input type="number" id="guess" />
<input type="button" onclick="doGuess()" value="Guess" />
<input type="button" onclick="reset()" value="Reset" />
<select id='num'>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
<hr>
<div id='log'></div>