I am trying to have this page allow the user to input heads or tails (case insensitive) into the first two boxes. The second two boxes show what two coins were flipped and the outcome box tells the user if they won or lost.
<html>
<head>
<title>Guess Two Coin Tosses</title>
<script>
function flip2(){
var guess1 = document.getElementById('guess1').value
var guess2 = document.getElementById('guess2').value
var flip1 = Math.floor(Math.random() * 2)
var flip2 = Math.floor(Math.random() * 2)
var outcomes
if (flip1 == guess1) {
if (flip2 == guess1)
outcomes = 'win win';
else
outcomes = 'win lose';
if (flip1 == 1)
flip1 = "Heads";
else
flip1 = "Tails" ;
if (flip2 == 1)
flip2 = "Heads";
else
flip2 = "Tails" ;
}
else {
if (flip2 == guess2)
outcomes = 'lose win';
else
outcomes = 'lose lose';
if (flip1 == 1)
flip1 = "Heads";
else
flip1 = "Tails" ;
if (flip2 == 1)
flip2 = "Heads";
else
flip2 = "Tails" ;
}
document.getElementById('flip1').value = flip1
document.getElementById('flip2').value = flip2
document.getElementById('outcomes').value = outcomes
}
</script>
</head>
<body>
<h3>Guess Two Coin Flips</h3>
Enter Heads for Heads, Tails for Tails
<p/>Your Guess for Flip-1:
<input type="text" id="guess1" size="5" value="" />
<p/>Your Guess for Flip-2:
<input type="text" id="guess2" size="5" value="" />
<p/>Flip-1:
<input type="text" id="flip1" size="5" value="???" />
<p/>Flip-2:
<input type="text" id="flip2" size="5" value="???" />
<p/><input type="button" value="Flip Two!"
onclick="flip2()" />
<p/>Outcomes:
<input type="text" id="outcomes" size="20" value="" />
</body>
</html>


Sign In
Create Account

Back to top









