-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHow many fingers are up.html
52 lines (49 loc) · 1.42 KB
/
How many fingers are up.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
<html>
<head>
<title>Javascript</title>
</head>
<body>
<p>How many finger are you holding up?</p>
<p>
<select id="myNumber">
<option>0</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
<button id="guess">Guess!</button>
</p>
<script type="text/javascript">
function doAGuess(correctAnswer) {
var guess = Math.random();
guess = guess * 6;
guess = Math.floor(guess);
if (guess == correctAnswer) {
return (true);
}
else {
return (false);
//Computer is wrong
}
}
document.getElementById("guess").onclick = function () {
var myNumber = document.getElementById("myNumber").value;
var gotIt = false;
var numberOfGuesses = 1;
while (gotIt == false) {
if (doAGuess(myNumber) == true) {
gotIt = true;
alert("Got it! It was a " + myNumber + ". It took me " + numberOfGuesses + " guesses.");
// Computer is correct
}
else {
numberOfGuesses++;
//Computer is wrong
}
}
}
</script>
</body>
</html>