-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path18 Functions Example.html
52 lines (51 loc) · 1.48 KB
/
18 Functions Example.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 lang="en">
<head>
<title>Fnnctons Example</title>
</head>
<!--In this code computer guesses how many fingers we are holding up using Functions
watch video functins in javascript from 6:00 -->
<body>
<p>How many fingers you are 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="ComputerGuess">Computer Guesses</button>
</p>
<script type="text/javascript">
function doAguess(correctnumber) {
// so correctnumber contains mynumberEnterted
var computerNumber = Math.floor(Math.random() * 6);
if (computerNumber == correctnumber) {
return true;
} else {
return false;
}
}
document.getElementById("ComputerGuess").onclick = function () {
var mynumberEnterted = document.getElementById("mynumber").value;
var gotIt = false;
var numberofGuesses = 1;
while (gotIt == false) {
if (doAguess(mynumberEnterted) === true) {
gotIt = true;
alert(
"Got It Right! It was a " +
mynumberEnterted +
" And It took PC " +
numberofGuesses +
" Guesses"
);
} else {
numberofGuesses++;
}
}
};
</script>
</body>
</html>