-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcoinFlip.html
More file actions
38 lines (36 loc) · 822 Bytes
/
coinFlip.html
File metadata and controls
38 lines (36 loc) · 822 Bytes
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
<style>
#guess {
width: 50px;
}
</style>
"Heads or Tails?"<br>
<input class="radio" type='radio' name='heads' id='heads' /> Heads<br>
<input class="radio" type='radio' name='tails' id='tails' /> Tails<br>
<input type='button' class='guess' name='guess' id='guess' value='Guess' /><br>
<label id='answer' text=''>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<script>
$('#guess').click(function(){
var randomNum = Math.floor((Math.random() * 2) + 1);
var guess = '';
var side = '';
if($('#heads').is(':checked'))
{
guess = '1';
side = "Heads";
}
else if($('#tails').is(':checked'))
{
guess = '2';
side = "Tails";
}
if(randomNum == guess)
{
$('#answer').text(side + " wins!");
}
else
{
$('#answer').text("You lose!");
}
});
</script>